ruby - Give argument to action on Rails -
how give argument action of controller.
i have action named action , controller named controller. want give argument action when go to
http://localhost:3000/controller/action/argument1 or to
http://localhost:3000/controller/action/argument2
how know, argument passed in action?
the documentation best place start. right top, there's example of passing in parameter (in case, id):
get '/patients/:id', to: 'patients#show'
(the line above go in routes.rb
file). id
param available in controller, in params[:id]
so in case, you'd have line in routes.rb
like:
get '/controller/action/:argument', to: 'controller#action'
and refer argument in controller params[:argument]
Comments
Post a Comment