2

I'm trying to switch to using image_submit_tag instead of submit_tag so I can have a nice looking button. But the parameter list is getting mangled:

<% form_tag 'reports', {:method => 'get'} do %>
    ...
    image_submit_tag("image.png", :name => 'filter')
    ...

This gets converted to the following HTML:

<form action="reports" method="get">
    ...
    <input name="filter" src="/images/add_filter.png?1391926927" type="image">
    ...

Looks good to me, but then when the controller function gets called, I get this for the param list:

{"filter.y"=>"9", "filter.x"=>"9", "controller"=>"reports", "action"=>"index"} 

I use the name to determine what button was pressed. How are the x and y values getting merged into my name? It works fine with regular submit_tag.

I found this thread which touches upon the x and y values, but doesn't mention why they'd get merged into the name field. Definitely strange. Any help is appreciated! No irrelevant criticism for still being on RoR 2.3 please.

Community
  • 1
  • 1
jsarma
  • 1,344
  • 11
  • 19

1 Answers1

1

This isn't great, but I just figured out that it works right if I specify both

:name => 'filter'

and

:value => 'filter'

It doesn't work if I specify just one or the other. And I still get filter.x and filter.y parameters, so it's kind of hackish. If anyone knows why this is, or has a less hackish workaround, I will choose your answer instead of this.

jsarma
  • 1,344
  • 11
  • 19
  • Tried also with just submit and specifiied `:src` with the same result. Seems like it sends coordinates of click place and nobody cares why... – Alexander Gorg Oct 14 '19 at 09:48
  • 1
    @AlexanderGorg W3C cares why, which is why they made the x and y params a standard part of the query string **when using image buttons**. You've probably figured out by now that these are the Cartesian coordinates of where the user clicked the image, measured from an origin in the upper left corner of the image. You can always use a different tag and give it an image via styling. – MarsAtomic Jul 23 '21 at 06:09
  • @MarsAtomic, thank you very much! These (x,y) were frustrating me all the time! – Alexander Gorg Jul 23 '21 at 09:40