开发者

Rails 3 - how to make a crossing? (routing)

开发者 https://www.devze.com 2023-04-08 16:23 出处:网络
I created a controller names. I have a model that contains a names of boys and girls (gender=0 for boys, 1 for girls).

I created a controller names. I have a model that contains a names of boys and girls (gender=0 for boys, 1 for girls). If I set to URL the address localhost:3000/names, so will be rendered the view index.html.erb. In this view is an overview of data that are stored in database.

I am trying to edit it - I want to have on the address localhost:3000/na开发者_运维问答mes a crossing - here will be 2 links - BOYS and GIRLS. And after click on one of these links I would like to go on the address localhost:3000/names/girls (or boys) and here I would like to have an overview of data from database...

I am newbie still and I don't know, how to realize it... mainly how to edit my routes.rb - I would like to ask you about a help, how to do it...

Thank you in advance


So you want a names_controller with actions boys and girls, and you want routes to those?

How about something like this:

resources(:names) do
  collection do
    get :boys
    get :girls
  end
end

Routes collection is documented here.

0

精彩评论

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