rails 4 route with parameter

Viewed 3344

Here is my route settings

resources :messages do
  collection do
    get 'message'
  end      
end

It works fine but I would like to add a parameter to this route

resources :messages do
  collection do
    get 'message/:username'
  end      
end

I got an error when I ran rake routes

rake aborted!
missing :action
/home/li/data/git/projectname/config/routes.rb:5:in `block (4 levels) in <top (required)>'
/home/li/data/git/projectname/config/routes.rb:4:in `block (3 levels) in <top (required)>'
/home/li/data/git/projectname/config/routes.rb:3:in `block (2 levels) in <top (required)>'
/home/li/data/git/projectname/config/routes.rb:2:in `block in <top (required)>'
/home/li/data/git/projectname/config/routes.rb:1:in `<top (required)>'
/home/li/data/git/projectname/config/environment.rb:5:in `<top (required)>'
Tasks: TOP => routes => environment
(See full trace by running task with --trace)

What is the right way to add a parameter to this route?

1 Answers
Related