Reputation: 1305
I have a Rails 4 application that is using form_for to build the form for a basic Blog type, everything is working as expected except for one thing: I have to determine the publish state of the blog based on the submit button chosen by the User when they submit the form. Here is the HAML code I have for that:
= form.submit 'Save as Draft', value: 'Draft', name: 'publish_state', class: 'button'
= form.submit 'Publish', value: 'Published', name: 'publish_state', class: 'button'
In this setup there are two different states Published
and Draft
, both are treated as Strings in the Database.
The issue that I'm having with this is that even though I am specifying the buttons to say 'Save as Draft'
and 'Publish'
they are only displaying based on their values, 'Draft'
and 'Published'
respectively. I have searched around and could only find how to either specify the value or the text, not separate the two. Is there a way in Rails forms to allow for this? Or, if not Rails forms, what are some other approaches that have worked?
===================
tl;dr - how can I make a button in Rails forms show one String and return a different one when clicked?
Upvotes: 2
Views: 1756
Reputation: 1079
You could use a generic button as the submit button.
= form.button 'Save as Draft', value: 'Draft', name: 'publish_state', class: 'button', type: 'submit'
= form.button 'Publish', value: 'Published', name: 'publish_state', class: 'button', type: 'submit'
Upvotes: 8