Home Submit Button in Rails partial on same line as Cancel button in parent view
Reply: 1

Submit Button in Rails partial on same line as Cancel button in parent view

Daiku
1#
Daiku Published in 2018-01-12 20:21:04Z

I have a basic rails form in a partial that is included in both my new and edit views. Those views both have a cancel button, but with different links (new goes to index, and edit goes to show) so it has to go in the parent, not the partial. I'd like the buttons rendered side by side, but not sure how to do that when one is in the form in the partial, and the other is not.

Tamer Shlash
2#
Tamer Shlash Reply to 2018-01-12 21:12:30Z

You could pass the cancel URL as a partial local variable, like this (assuming your model is called Post):

# In new.html.erb

<h1>New Post</h1>
<%= render partial: "form", locals: {post: @post, cancel_url: posts_path} %>


# In edit.html.erb

<h1>Edit Post</h1>
<%= render partial: "form", locals: {post: @post, cancel_url: post_path(@post)} %>


# In _form.html.erb

<%= link_to 'Cancel', cancel_url %>
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.40082 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO