Forum: Ruby on Rails start_form_tag not taking url_for options

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
42172acdf3c6046f84d644cb0b94642c?d=identicon&s=25 Pat Maddox (pergesu)
on 2006-01-19 13:07
(Received via mailing list)
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 <form action="/">

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

Pat
337cdd270761e0e6f4356de45b04d388?d=identicon&s=25 Jonathan Viney (Guest)
on 2006-01-19 14:01
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 Maddox 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 <form action="/">
>
> Not sure what's going on..I need to be able to specify the controller
> and action that the form posts to.
>
> Pat
42172acdf3c6046f84d644cb0b94642c?d=identicon&s=25 Pat Maddox (pergesu)
on 2006-01-19 14:07
(Received via mailing list)
When I do that, it's still generating the wrong form tag:
<form action="/" method="post">
C8a634a01a2c4508360874bff7fb1a7f?d=identicon&s=25 Kevin Olbrich (olbrich)
on 2006-01-19 14:13
Pat Maddox wrote:
> When I do that, it's still generating the wrong form tag:
> <form action="/" method="post">

What do you get if you just stick in a

url_for :controller=>'user', :action=>'login'

?

_Kevin
42172acdf3c6046f84d644cb0b94642c?d=identicon&s=25 Pat Maddox (pergesu)
on 2006-01-19 14:22
(Received via mailing list)
On 1/19/06, Kevin Olbrich <kevin.olbrich@duke.edu> wrote:
> _Kevin
>
>
> --
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>

I just tried:
<form action="<%= url_for :controller=>'user', :action=>'login' %>"
method="post">

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
42172acdf3c6046f84d644cb0b94642c?d=identicon&s=25 Pat Maddox (pergesu)
on 2006-01-19 14:31
(Received via mailing list)
On 1/19/06, Pat Maddox <pergesu@gmail.com> 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
2f46d76f0e5db4dc318b03be07ebaac4?d=identicon&s=25 Tom Ward (Guest)
on 2006-01-19 14:35
(Received via mailing list)
> I just tried:
> <form action="<%= url_for :controller=>'user', :action=>'login' %>"
> method="post">
>
> 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
42172acdf3c6046f84d644cb0b94642c?d=identicon&s=25 Pat Maddox (pergesu)
on 2006-01-19 14:38
(Received via mailing list)
> 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
82476266af9d460415d8f1fc16bb54ed?d=identicon&s=25 Jarkko Laine (jarkko)
on 2006-01-19 14:41
(Received via mailing list)
On 19.1.2006, at 14.53, Pat Maddox 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
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>

--
Jarkko Laine
http://jlaine.net
http://odesign.fi
2f46d76f0e5db4dc318b03be07ebaac4?d=identicon&s=25 Tom Ward (Guest)
on 2006-01-19 14:44
(Received via mailing list)
On 1/19/06, Pat Maddox <pergesu@gmail.com> 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
This topic is locked and can not be replied to.