开发者

Matching routes in rails3 only works for first route

I have these two routes for static pages which I catch in the controller.

  match "/pages/:page" => "pages#aboutus"
  match "/pages/:page" => "pages#team"

I thought that it would work by matching the "aboutus" or the "team" but the routing seems to only be working by looking for the first entry above.

My controller looks like this:

  def aboutus
  end  

  def team
  end

Any idea how I can make the routes go to the cor开发者_运维技巧rect controller entry?

Thanks!


It can't work like that.

What you wrote means that the request is dispatched to the pages controller’s aboutus action with { :page } in params. What is supposed to be your :page ?

Also, read the routing guide

If you want /pages/aboutus to redirect to pages#aboutus and /pages/team/ to pages#team do that:

match "/pages/aboutus" => "pages#aboutus"
match "/pages/team" => "pages#team"


The match goes against the name in the name/value pair. You could do something like this instead:

match "/pages/about-us" => "pages#aboutus"
match "/pages/team" => "pages#team"

If you're looking for global solution to handle static pages, however, I recommend highvoltage by thoughtbot:

https://github.com/thoughtbot/high_voltage


This won't work, sorry. You're trying to use the same url to go to two different places. That first parameter to match is how the url looks in the browser, and you've given the exact same one to the two routes.

You need to differentiate the urls somehow.

Are you actually trying to do this:

match "/pages/aboutus" => "pages#aboutus"
match "/pages/team" => "pages#team"
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜