how to use variable name with image tag
my controller uses code like this:
if params[:commit] == "Submit"
this used to开发者_运维问答 work fine when I just had buttons. however, now I am using images as buttons like below:
<%= image_submit_tag 'butons/Add-08.png', :class => 'image-button-submit' %>
How can I pass the commit
variable with value Submit
along with this image_submit_tag
?
KandadaBoggu is right, but that will (in most browsers) give you a params['commit.x']
and params['commit.y']
rather than just params['commit']
.
If there's only the one button on the form (and you're posting to the same action that renders the form) you can do if request.post?
instead, but that's only going to work if there's just one button, ie: only submit, not submit and cancel.
As per the image_submit_tag documentation you can pass any HTML options. I haven't tested this but the following code should work.
<%= image_submit_tag 'butons/Add-08.png', :name =>"commit", :value =>"Submit" %>
I would try passing it as a hidden field inside of the form you're submitting.
hidden_field_tag "commit", "Submit"
精彩评论