Rails: Render Form on Index -


i want able use <%= render 'form' %> on index page. correct way go that? appears work, however, want ensure correct method of doing this.

class reminderscontroller < applicationcontroller   ...      def index       @reminders = reminder.all       @reminder = reminder.new      end .... 

there nothing wrong including 'new'/'edit' form in index view. it's not 'normal' rails way work. remember, once filled out form on page, still need submit form (you can submit 1 @ time). kinda gets tricky. if want create , update reminders same page, must have different forms different actions. 'new' form like:

<%= form_for @reminder, url: {controller: "reminders", action: "create"} |r| %>   <form code goes here>   <%= r.submit %> <% end %> 

and 'edit' form(s) like:

<%= @reminders.each |reminder| %>   <%= form_for reminder, url: {controller: "reminders", action: "update"} |r| %>     <form code goes here>     <%= r.submit %>   <% end %> <% end %> 

edit

if want entire form inside _form.html.erb partial, can pass in url paramater, this:

<%= render partial: 'form', locals: {path: {controller: "reminders", action: (create/update)}} %> 

and inside partial:

<%= form_for @reminder, url: path %> 

Comments

Popular posts from this blog

javascript - How to synchronize the Three.js and HTML/SVG coordinate systems (especially w.r.t. the y-axis)? -

javascript - How do I find how many occurences are there of a highlighted string, and which occurence is it? -

java - Reading data from multiple zip files and combining them to one -