3

What I have

match "/home/markread/:id" => "books#markread"

goes to

def markread
  #mark params[:id] as read
end

What I want

What If I want to pass another parameter so that urls looks like /home/markread/1/didread=read or /home/markread/1/didread=unread

so my method will change to

def marked
  #mark params[:id] as params[:didread]
end

Question

what should my routes.rb look like for me to achieve this?

3 Answers 3

5

How about just changing to

match "home/markread/:id/used=:used" => "books#markread"
Sign up to request clarification or add additional context in comments.

Comments

3

Give the route a name using the 'as' option and pass the optional parameters as many you want.

For example:

match "/home/markread/:id" => "books#markread", :as => 'markread'

This will give you helpers like, markread_path and markread_url. You can pass the parameters like markread_path(:id => 1, :other => 'value' ...)

You need to do the checks in the controller for that action whether a particular parameter is passed or not. Rails Doc.

2 Comments

from the example you provided...will I still be able to pass in more than one parameter?
Yes. You can pass in as many parameters as you want. Decide what you want to do with them in the controller.
1

In rails 4 you will have:

    resources :home, only: :none do
      get 'markread/:another', action: :markread, on: :member
    end

GET /home/:id/markread/:another(.:format) /home#markread

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.