ruby on rails - How Do I pass parameters with a render call? -
this simple question. if form isn't filled out correctly, call render 'new'
in create action person can fill out form correctly. unfortunately, causes loss of parameters in url. how pass them along render call?
your action method should pick parameters , assign instance variable. model in example called note.
def create @note = note.new(params[:note]) respond_to |format| if @note.save format.html { redirect_to @note, notice: 'note created.' } else format.html { render action: "new" } end end end
the instance variable visible within view:
<%= form_for(@note) |f| %> <%= f.text_field :name %> <%= f.submit %> <% end %>
Comments
Post a Comment