Currently, I have several forms that I am trying to change a button that sends it if I am in an edit action or a new action. I had two forms, but it smelled bad, and now I just use only one form.
At the end of my partial, I have something like this at the end of my forms:
<p> <% if controller.action_name == 'new' %> <%= f.submit "Create", :class => "pink_button"%> or <% elsif controller.action_name == 'edit' %> <%= f.submit "Update", :class => "pink_button"%> or <% end %> <%= link_to "cancel", :back %> </p>
Thus, if I create a new one, the button reads “Create,” and if it is an update that the user is trying to complete, the button reads “Update.” This works fine until the form is submitted and validation fails.
In my controller, I break things that don't work like this:
def update @list = current_user.lists.find(params[:id]) if @list.update_attributes(params[:list]) redirect_to list_path(@list), :notice => "List '#{@list.name}' updated." else render :action => 'edit' end end
Thus, the form is simply redrawn. The problem is that I'm no longer on the path of editing. This means that my form button is no longer displayed.
Is there an agreement on what I'm trying to do?
thanks
Kombo source share