I have a _form partial which rails automatically names the submit buttons for me, for new and edit views. In the new view I prefer for the submit button value to simply read “Create” instead of “Create Link”
I achieved this with <%= form.submit "Create" %>
How would I make rails display <%= form.submit "Update" %> in the edit view and <%= form.submit "Create" %> in the new, pending which view ‘_form.html.erb’ is being rendered in? Thanks
Well I’m assuming you pass in an object, like
@userfor instance. In that case, within your _form, do this:I made separate editing and default_text variables here but you could do it in one line like:
The only reason why I showed you the variables is because it’s easily scalable to other text you have on your form.
Edit I should also mention that the point of using
new_record?works if for a new User (for example) you simply set @user to be User.new in your controller, but for editing you do User.find(…).