I want to pass id from view to controller. I know how to pass it by assigning a name to it like : :eid => @model["_id"]. And then I can fetch in controller using params[:"_id"].
But then the url would be /create?:eid="1234". But I want this: create/1234. So how can I do that
- In view
- How to fetch in controller.
You should spend some time learning about routes. You’ll need to define a route to do what you want to do.
In your
config/routes.rbThen, in your view:
I’ll also suggest that the path of your route probably ought to be more descriptive that just
/create/:_idbut in the spirit of answering your question I’ve left it as such.