Start_form_tag not taking url_for options


#1

I’ve got a form that should post to user/login. The code to start the
tag is:
<%= start_form_tag { :controller => “user”, :action => “login” } %>

That gives me this exception:
compile error
script/…/config/…/app/views/user/login.rhtml:1: parse error,
unexpected tASSOC, expecting ‘}’
_erbout = ‘’; _erbout.concat(( start_form_tag { :controller => “user”,
:action => “login” } ).to_s); _erbout.concat “\n”
^
script/…/config/…/app/views/user/login.rhtml:1: parse error,
unexpected ‘,’, expecting ‘}’
_erbout = ‘’; _erbout.concat(( start_form_tag { :controller => “user”,
:action => “login” } ).to_s); _erbout.concat “\n”

However if I do:
<%= start_form_tag({ :controller => “user”, :action => “login” }) %>

it just spits out a form

Not sure what’s going on…I need to be able to specify the controller
and action that the form posts to.

Pat


#2

My guess would be that the first example is giving an error because it
thinks you are passing a code block, not a hash, and the code block has
syntax errors.

This should work:

<%= form_tag :controller => ‘user’, :action => ‘login’ %>

Cheers, Jonathan.

Pat M. wrote:

I’ve got a form that should post to user/login. The code to start the
tag is:
<%= start_form_tag { :controller => “user”, :action => “login” } %>

That gives me this exception:
compile error
script/…/config/…/app/views/user/login.rhtml:1: parse error,
unexpected tASSOC, expecting ‘}’
_erbout = ‘’; _erbout.concat(( start_form_tag { :controller => “user”,
:action => “login” } ).to_s); _erbout.concat “\n”
^
script/…/config/…/app/views/user/login.rhtml:1: parse error,
unexpected ‘,’, expecting ‘}’
_erbout = ‘’; _erbout.concat(( start_form_tag { :controller => “user”,
:action => “login” } ).to_s); _erbout.concat “\n”

However if I do:
<%= start_form_tag({ :controller => “user”, :action => “login” }) %>

it just spits out a form

Not sure what’s going on…I need to be able to specify the controller
and action that the form posts to.

Pat


#3

When I do that, it’s still generating the wrong form tag:


#4

Pat M. wrote:

When I do that, it’s still generating the wrong form tag:

What do you get if you just stick in a

url_for :controller=>‘user’, :action=>‘login’

?

_Kevin


#5

On 1/19/06, Pat M. removed_email_address@domain.invalid wrote:

Pat

Okay I might be getting a little bit closer…
url_for :controller => ‘user’, :action => ‘login’ apparently returns ‘/’

If I change the controller to anything else, I get the expected url.
If I change the action to anything else, I get the expected url. Just
can’t use this combo, apparently.

Now I think I’ve really figured it out…in my routes.rb file I have:
map.connect ‘’, :controller => “user”, :action => “login”

So I guess url_for uses routes to generate the urls? Not sure…is
there any way I can make user/login respond to the app root, and still
be able to use url_for in other places?

Pat


#6

I just tried:

instead of using start_form_tag, and I get the same thing still…I
wonder if webrick might be caching it or something?

To ease your fears, try adding ‘id=“something”’ to your form
declaration - if you see that in the source reaching the browser, you
know nothing is being cached anywhere down the chain.

Assuming caching isn’t the issue, what url do you expect to get? Have
you changed routing.rb to map / to user/login?

Tom


#7

Assuming caching isn’t the issue, what url do you expect to get? Have
you changed routing.rb to map / to user/login?
Yeah, I did…is that what’s causing this? I’m kind of guessing so,
but I didn’t know that url_for uses routes to generate the urls. It
seems as if I map / after the default route, everything works fine:

Install the default route as the lowest priority.

map.connect ‘:controller/:action/:id’
map.connect ‘’, :controller => “user”, :action => “login”

Does that sound right to you?

Pat


#8

On 1/19/06, Kevin O. removed_email_address@domain.invalid wrote:

_Kevin


Posted via http://www.ruby-forum.com/.


Rails mailing list
removed_email_address@domain.invalid
http://lists.rubyonrails.org/mailman/listinfo/rails

I just tried:

instead of using start_form_tag, and I get the same thing still…I
wonder if webrick might be caching it or something? I’ve cleared the
cache on my browser multiple times, used a different browser, and even
tried connecting from a different computer. I haven’t turned any
caching on in rails, so unless it’s on by default somewhere, I don’t
know why anything would be cached.

Pat


#9

On 1/19/06, Pat M. removed_email_address@domain.invalid wrote:

Assuming caching isn’t the issue, what url do you expect to get? Have
you changed routing.rb to map / to user/login?

Yeah, I did…is that what’s causing this? I’m kind of guessing so,
but I didn’t know that url_for uses routes to generate the urls. It
seems as if I map / after the default route, everything works fine:

url_for does use routes to generate urls. this gives you loads of
flexibility when changing your url schemes, assuming you’ve used
url_for throughout your app.

Install the default route as the lowest priority.

map.connect ‘:controller/:action/:id’
map.connect ‘’, :controller => “user”, :action => “login”

Looks good

Tom


#10

On 19.1.2006, at 14.53, Pat M. wrote:

So I guess url_for uses routes to generate the urls?

Most definitely, that’s the (half of) idea behind routing and using
these url helpers. They will change according to your needs. However,
url_for will use the first route that matches, so you can put this
above the route you mention:

map.connect ‘user/login’, :controller => “user”, :action => “login”

That way, both url’s map to the same controller but the url
generation in Rails uses the user/login one.

//jarkko

Not sure…is
there any way I can make user/login respond to the app root, and still
be able to use url_for in other places?

Pat


Rails mailing list
removed_email_address@domain.invalid
http://lists.rubyonrails.org/mailman/listinfo/rails


Jarkko L.
http://jlaine.net
http://odesign.fi