aris
September 20, 2012, 3:34am
1
I have a controller:
class HomeController < ApplicationController
def index
end
def about
end
def contact
end
def terms
end
def privacy
end
end
My routes.rb has:
resources :home do
member do
get ‘about’
get ‘contact’
get ‘terms’
get ‘privacy’
end
end
In my application.html.erb I have:
About
It seems to be expecting an id?
I’m getting the error:
No route matches {:action=>“about”, :controller=>“home”}
Rake routes shows:
about_home GET /home/:id/about(.:format) home#about
S_Ahmed
September 20, 2012, 3:55am
2
Maybe it could be a inflection problem:
“home”.pluralize
“homes”
The convention is that a controller is the pluralized name of the model.
S_Ahmed
September 20, 2012, 3:58am
3
Use “collection” instead “member”
Rails Routing from the Outside InThis guide covers the user-facing features of Rails routing.After reading this guide, you will know: How to interpret the code in config/routes.rb. How to construct your own routes, using either the preferred...
2012/9/19 S Ahmed [email protected]
def contact
In my application.html.erb I have:
For more options, visit https://groups.google.com/groups/opt_out .
–
Fernando A.
S_Ahmed
September 20, 2012, 4:01am
4
Thanks, that worked. Although it doesn’t make sense, it isnt’ a
colleciton
so I guessed to use member.
BTW, how could I match this:
/home/some-name-here
Where ‘some-name-here’ is the parameter (id), and I want to call
home#show
On Wed, Sep 19, 2012 at 9:56 PM, Fernando A. <
S_Ahmed
September 20, 2012, 4:15am
5
You can use
match ‘home/:page’ => ‘home#page’ <<<< before
resources :home <<<< after
home_controller
def page
use params[:page]
end
Rails routes are matched in the order they are specified, so if you
have a resources
:photos above a get ‘photos/poll’ the show actions route for the
resourcesline will be matched before the
get line. To fix this, move the get line above the resources line so
that
it is matched first.
Rails Routing from the Outside InThis guide covers the user-facing features of Rails routing.After reading this guide, you will know: How to interpret the code in config/routes.rb. How to construct your own routes, using either the preferred...
2012/9/19 S Ahmed [email protected]
On Wed, Sep 19, 2012 at 9:56 PM, Fernando A. <
def index
end
get ‘contact’
It seems to be expecting an id?
To post to this group, send email to [email protected] .
To post to this group, send email to [email protected] .
To unsubscribe from this group, send email to
[email protected] .
For more options, visit https://groups.google.com/groups/opt_out .
–
Fernando A.
S_Ahmed
September 20, 2012, 4:33am
6
Not if defined before the resource.
2012/9/19 Jim Ruther N. [email protected]
a resources :photos above a get ‘photos/poll’ the show actions route
end
def privacy
get ‘privacy’
I’m getting the error:
You received this message because you are subscribed to the Google
To unsubscribe from this group, send email to
To unsubscribe from this group, send email to
www.fernandoalmeida.net
To post to this group, send email to [email protected] .
To unsubscribe from this group, send email to
[email protected] .
For more options, visit https://groups.google.com/groups/opt_out .
–
Fernando A.
S_Ahmed
September 20, 2012, 4:26am
7
On Thu, Sep 20, 2012 at 12:13 PM, Fernando A. <
[email protected] > wrote:
You can use
match ‘home/:page’ => ‘home#page’ <<<< before
resources :home <<<< after
this isn’t advisable. home/:page will match home/1
Rails Routing from the Outside In — Ruby on Rails Guides
/home/some-name-here
2012/9/19 S Ahmed [email protected]
My routes.rb has:
For more options, visit https://groups.google.com/groups/opt_out .
To unsubscribe from this group, send email to
[email protected] .
For more options, visit https://groups.google.com/groups/opt_out .
–
S_Ahmed
September 20, 2012, 4:51am
8
On Thu, Sep 20, 2012 at 12:32 PM, Fernando A. <
[email protected] > wrote:
Not if defined before the resource.
i’m not saying that it won’t work. i’m saying that it’s not good
practice.
i would’ve agreed
with your method if you added constraints to values of the :page
parameter.
use params[:page]
home#show
I have a controller:
end
resources :home do
–
To unsubscribe from this group, send email to
visit my blog at http://jimlabs.heroku.com
To post to this group, send email to [email protected] .
To unsubscribe from this group, send email to
[email protected] .
For more options, visit https://groups.google.com/groups/opt_out .
–
S_Ahmed
September 20, 2012, 5:00am
9
hummm… really, I agree with you.
2012/9/19 Jim Ruther N. [email protected]
with your method if you added constraints to values of the :page parameter.
home_controller
2012/9/19 S Ahmed [email protected]
My routes.rb has:
To unsubscribe from this group, send email to
www.fernandoalmeida.net
For more options, visit https://groups.google.com/groups/opt_out .
–
[email protected] .
To unsubscribe from this group, send email to
[email protected] .
For more options, visit https://groups.google.com/groups/opt_out .
–
Fernando A.