简体   繁体   中英

Custom routing and get ids from url

I have a model name "profit" and it has a table name profits and 3 column of the table "price", "sell", "grossprofit"

Now in my index.html.erb page I have option for show as

<td><%= link_to 'Show', profit %></td>

when I click on the show link i go to show page and link become

http://localhost:3000/students/1
http://localhost:3000/students/2

that is i am getting id of profits table but I need price and sell in my url like below

http://localhost:3000/students/3/5

where 3 will be sell and 5 will be price

What changes I have to do to get this url and how can I get price and sell from the url in show action of the controller?

create route like this in routes.rb. put this before resources :students

get '/students/:sell/:price, to: "students#show"

now run rake routes and see what helper it will create and use that

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM