Gavin Sinclair
2005-May-01 01:21 UTC
start_form_tag has a design problem with its parameters
After writing heaps of link_to "blah", { :action => ''foo'', :id => id }, :class => ''widget'' I kinda got used to that pattern for the parameters: URL options go in their own hash; HTML options are listed afterwards. So when I tried to edit a form tag, I did this start_form_tag { :action => ''foo'' }, :name => ''bar'' and it didn''t work. The Rails API doc tells me that it''s correct (i.e. start_form_tag(url_for_options = {}, options = {}, *params_for_url) but a subtle Ruby factor prevents the above line from working. Ruby interprets the above line as though { :action => ''foo'' } were a block, not a hash, and raises a syntax error when it encounters the ", :name => ''bar''". The reason this coding style works for link_to and not start_form_tag is because link_to has the mandatory first (string) parameter, which means the "{" is not thought of as the beginning of a block. It''s a shame I can''t code similar constructs the same way, but I doubt much can/will be done about it. File under "annoyance". BTW to get the above line to work: start_form_tag({ :action => ''foo'' }, :name => ''bar'') Gavin