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
Post a Comment