开发者

Rails - Proper way to route an action in a controller

I'm trying to create a button that performs some actions from my controller when clicked, but I'm getting some routing errors.

The button in the view looks like...

  <%= button_to "Thumbs Up", {:controller => 'user', :action => "yes", :id => event.id}  %>

The view is the index page of the my user controller. Within the user controller I have an action called "yes" that makes changes to a record depending on which Event(the model being displayed on the index page) item is picked. SO the controller action in the controller looks like....

def yes
  @user = User.find(current_user)
  @event = Event.find(params[:id])
 ........ Blah Blah Blah ....开发者_如何学Go.
  redirect_to home_path
end

The home path is just routing to the user#index view

So for the route I have is ....

  match '/yes' => 'user#yes'.

But I get the error "No route matches {:controller=>"user/user", :action=>"yes", :id=>1}"

So how do I create a button and route that goes to a specific action in my controller and passes the id as the parameter so the action can work its magic and redirect to the same page?


  match '/yes(/:id)' => 'user#yes'

brackets make params optionnal, see http://edgeguides.rubyonrails.org/routing.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜