Forum: Ruby on Rails Rails3 routes

Posted by Shandy Nantz (snantz)
on 2012-07-19 18:19
Hi all,

I'm trying to convert what I think are some pretty straight forward
Rail2 routes to Rails3 routes with no success.

I have map.connect '', :controller => "agency" which I have tried
converting to match '', :to => 'agency' which then throws an error
saying:

/home/shandy/.rvm/gems/ruby-1.8.7-p370/gems/actionpack-3.2.2/lib/action_dispatch/routing/mapper.rb:183:in
`default_controller_and_action': missing :action (ArgumentError)
        from
/home/shandy/.rvm/gems/ruby-1.8.7-p370/gems/actionpack-3.2.2/lib/action_dispatch/routing/mapper.rb:76:in
`normalize_options!'
        from
/home/shandy/.rvm/gems/ruby-1.8.7-p370/gems/actionpack-3.2.2/lib/action_dispatch/routing/mapper.rb:59:in
`initialize'
        from
/home/shandy/.rvm/gems/ruby-1.8.7-p370/gems/actionpack-3.2.2/lib/action_dispatch/routing/mapper.rb:1302:in
`new'
        from
/home/shandy/.rvm/gems/ruby-1.8.7-p370/gems/actionpack-3.2.2/lib/action_dispatch/routing/mapper.rb:1302:in
`add_route'
        from
/home/shandy/.rvm/gems/ruby-1.8.7-p370/gems/actionpack-3.2.2/lib/action_dispatch/routing/mapper.rb:1282:in
`decomposed_match'
        from
/home/shandy/.rvm/gems/ruby-1.8.7-p370/gems/actionpack-3.2.2/lib/action_dispatch/routing/mapper.rb:1268:in
`match'
        from
/home/shandy/.rvm/gems/ruby-1.8.7-p370/gems/actionpack-3.2.2/lib/action_dispatch/routing/mapper.rb:1268:in
`each'
        from
/home/shandy/.rvm/gems/ruby-1.8.7-p370/gems/actionpack-3.2.2/lib/action_dispatch/routing/mapper.rb:1268:in
`match'
        from /home/shandy/npower/config/routes.rb:74
        from
/home/shandy/.rvm/gems/ruby-1.8.7-p370/gems/actionpack-3.2.2/lib/action_dispatch/routing/route_set.rb:276:in
`instance_exec'
        from
/home/shandy/.rvm/gems/ruby-1.8.7-p370/gems/actionpack-3.2.2/lib/action_dispatch/routing/route_set.rb:276:in
`eval_block'
        from
/home/shandy/.rvm/gems/ruby-1.8.7-p370/gems/actionpack-3.2.2/lib/action_dispatch/routing/route_set.rb:254:in
`draw'
        from /home/shandy/npower/config/routes.rb:1
        from
/home/shandy/.rvm/gems/ruby-1.8.7-p370/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:245:in
`load'
        from
/home/shandy/.rvm/gems/ruby-1.8.7-p370/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:245:in
`load'
        from
/home/shandy/.rvm/gems/ruby-1.8.7-p370/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:236:in
`load_dependency'
        from
/home/shandy/.rvm/gems/ruby-1.8.7-p370/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:245:in
`load'
        from
/home/shandy/.rvm/gems/ruby-1.8.7-p370/gems/railties-3.2.2/lib/rails/application/routes_reloader.rb:40:in
`load_paths'
        from
/home/shandy/.rvm/gems/ruby-1.8.7-p370/gems/railties-3.2.2/lib/rails/application/routes_reloader.rb:40:in
`each'
        from
/home/shandy/.rvm/gems/ruby-1.8.7-p370/gems/railties-3.2.2/lib/rails/application/routes_reloader.rb:40:in
`load_paths'
        from
/home/shandy/.rvm/gems/ruby-1.8.7-p370/gems/railties-3.2.2/lib/rails/application/routes_reloader.rb:16:in
`reload!'
        from
/home/shandy/.rvm/gems/ruby-1.8.7-p370/gems/railties-3.2.2/lib/rails/application/routes_reloader.rb:26:in
`updater'
        from
/home/shandy/.rvm/gems/ruby-1.8.7-p370/gems/activesupport-3.2.2/lib/active_support/file_update_checker.rb:78:in
`call'
        from
/home/shandy/.rvm/gems/ruby-1.8.7-p370/gems/activesupport-3.2.2/lib/active_support/file_update_checker.rb:78:in
`execute'
        from
/home/shandy/.rvm/gems/ruby-1.8.7-p370/gems/railties-3.2.2/lib/rails/application/routes_reloader.rb:27:in
`updater'
        from
/home/shandy/.rvm/gems/ruby-1.8.7-p370/gems/railties-3.2.2/lib/rails/application/routes_reloader.rb:7:in
`execute_if_updated'
        from
/home/shandy/.rvm/gems/ruby-1.8.7-p370/gems/railties-3.2.2/lib/rails/application/finisher.rb:66
        from
/home/shandy/.rvm/gems/ruby-1.8.7-p370/gems/railties-3.2.2/lib/rails/initializable.rb:30:in
`instance_exec'
        from
/home/shandy/.rvm/gems/ruby-1.8.7-p370/gems/railties-3.2.2/lib/rails/initializable.rb:30:in
`run'
        from
/home/shandy/.rvm/gems/ruby-1.8.7-p370/gems/railties-3.2.2/lib/rails/initializable.rb:55:in
`run_initializers'
        from
/home/shandy/.rvm/gems/ruby-1.8.7-p370/gems/railties-3.2.2/lib/rails/initializable.rb:54:in
`each'
        from
/home/shandy/.rvm/gems/ruby-1.8.7-p370/gems/railties-3.2.2/lib/rails/initializable.rb:54:in
`run_initializers'
        from
/home/shandy/.rvm/gems/ruby-1.8.7-p370/gems/railties-3.2.2/lib/rails/application.rb:136:in
`initialize!'
        from
/home/shandy/.rvm/gems/ruby-1.8.7-p370/gems/railties-3.2.2/lib/rails/railtie/configurable.rb:30:in
`send'
        from
/home/shandy/.rvm/gems/ruby-1.8.7-p370/gems/railties-3.2.2/lib/rails/railtie/configurable.rb:30:in
`method_missing'
        from /home/shandy/npower/config/environment.rb:5
        from /home/shandy/npower/config.ru:4:in `require'
        from /home/shandy/npower/config.ru:4
        from
/home/shandy/.rvm/gems/ruby-1.8.7-p370/gems/rack-1.4.1/lib/rack/builder.rb:51:in
`instance_eval'
        from
/home/shandy/.rvm/gems/ruby-1.8.7-p370/gems/rack-1.4.1/lib/rack/builder.rb:51:in
`initialize'
        from /home/shandy/npower/config.ru:1:in `new'
        from /home/shandy/npower/config.ru:1

I have also tried

 Npower::Application.routes.draw do
    match 'login', :to => 'agency'
 end

But then I get an error that says "No route matches [GET] "/agency"." If
anybody has any ideas or could point me to a site that explains the
differences/conversions of Rails2 routes to Rails3 routes, that would
much appreciated. Thanks,

-S
Posted by Colin Law (Guest)
on 2012-07-19 21:45
(Received via mailing list)
On 19 July 2012 17:19, Shandy Nantz <lists@ruby-forum.com> wrote:
> Hi all,
>
> I'm trying to convert what I think are some pretty straight forward
> Rail2 routes to Rails3 routes with no success.
>
> I have map.connect '', :controller => "agency" which I have tried
> converting to match '', :to => 'agency' which then throws an error
> saying:

Is that not just
root :to => "agency#index"
assuming the action you want is index.  Unless I have forgotten how
rails 2 routing worked.

Colin
Posted by Shandy Nantz (snantz)
on 2012-07-20 17:24
Colin Law wrote in post #1069377:
> On 19 July 2012 17:19, Shandy Nantz <lists@ruby-forum.com> wrote:
>
> Is that not just
> root :to => "agency#index"
> assuming the action you want is index.  Unless I have forgotten how
> rails 2 routing worked.
>
> Colin

That's what I thought, but I keep getting "No route matches [GET]
"/agency/login"" error, so I'm wonder if I have something else setup
incorrectly. Thanks for the response,

-S
Posted by Colin Law (Guest)
on 2012-07-20 18:32
(Received via mailing list)
On 20 July 2012 16:24, Shandy Nantz <lists@ruby-forum.com> wrote:
> That's what I thought, but I keep getting "No route matches [GET]
> "/agency/login"" error, so I'm wonder if I have something else setup
> incorrectly. Thanks for the response,

What url are you using that gives that?

Colin
Posted by Gintautas S. (gintautas_s)
on 2012-07-20 18:45
(Received via mailing list)
Hey Shandy, use

match '', :to => 'agency#index'

or replace index with another agency controller action explicitly.

In order to solve the second problem we'd need your routes.rb file 
(please
use pastie.org or simple code formatting to make it easy to read.

2012/7/20 Colin Law <clanlaw@googlemail.com>
Posted by Colin Law (Guest)
on 2012-07-20 22:07
(Received via mailing list)
On 20 July 2012 17:44, Gintautas Šimkus <dihitales@gmail.com> wrote:
> Hey Shandy, use
>
> match '', :to => 'agency#index'

Is that better then root :to=>... ?

Colin
Posted by Shandy Nantz (snantz)
on 2012-07-20 22:38
Colin Law wrote in post #1069541:
> On 20 July 2012 17:44, Gintautas Šimkus <dihitales@gmail.com> wrote:
>> Hey Shandy, use
>>
>> match '', :to => 'agency#index'
>
> Is that better then root :to=>... ?
>
> Colin

When I do that I get this error:

 syntax error, unexpected ':', expecting kEND (SyntaxError)
  match '' :to => 'agency#index'
            ^

I'm not sure if I have some issue with my rails setup, but it seems like
everything I try it either doesn't work as expected, or errors when I 
stat
the server. I'm running rails 3.2.2. Thanks for the suggestion,

-S
Posted by Colin Law (Guest)
on 2012-07-20 22:42
(Received via mailing list)
On 20 July 2012 21:38, Shandy Nantz <lists@ruby-forum.com> wrote:
> When I do that I get this error:
>
>  syntax error, unexpected ':', expecting kEND (SyntaxError)
>   match '' :to => 'agency#index'
>             ^
>
> I'm not sure if I have some issue with my rails setup, but it seems like
> everything I try it either doesn't work as expected, or errors when I
> stat
> the server. I'm running rails 3.2.2. Thanks for the suggestion,

So what happens with root :to?
Show us the exact line you have in routes.rb, what url you are asking
for and what happens.

Colin
Posted by Shandy Nantz (snantz)
on 2012-07-20 23:02
Colin Law wrote in post #1069548:
> On 20 July 2012 21:38, Shandy Nantz <lists@ruby-forum.com> wrote:
>
> So what happens with root :to?
> Show us the exact line you have in routes.rb, what url you are asking
> for and what happens.
>
> Colin

That works fine, in that the server starts. I'm still unable to bring up 
a specific page. I get: No route matches [GET] "/agency/login"

-S
Posted by Colin Law (Guest)
on 2012-07-20 23:14
(Received via mailing list)
On 20 July 2012 22:02, Shandy Nantz <lists@ruby-forum.com> wrote:
> a specific page. I get: No route matches [GET] "/agency/login"
You still have not told us what url you are asking for when that
happens, and exactly what you have specified for root :to=>

Colin
Posted by Colin Law (Guest)
on 2012-07-25 09:12
(Received via mailing list)
On 20 July 2012 22:12, Colin Law <clanlaw@googlemail.com> wrote:
>> That works fine, in that the server starts. I'm still unable to bring up
>> a specific page. I get: No route matches [GET] "/agency/login"
>
> You still have not told us what url you are asking for when that
> happens, and exactly what you have specified for root :to=>

It is rather depressing how often this happens.  A question is asked
but the OP never responds.  Presumably the OP realised his mistake in
the process of answering the question but does not have the good
manners to reply. :(

Colin
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.