Clarification on how to use “thumbs_up” voting gem with Rails 3

后端 未结 3 790
悲&欢浪女
悲&欢浪女 2020-11-30 03:27

I am attempting to implement the thumbs_up voting gem on a Rails 3 app, however the instructions are unclear on the actual implementation. After requiring the gem [g

3条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-30 04:13

    This is just a continuation of Brady's answer.

    Brady had the following code in his view

    <%= link_to('vote for this post!', vote_up_post_path(@post), :method => :post) %>
    

    what he means is.. since link_to by default uses :method => 'get' & he wanted to update the record using post & not get so he is using :method => 'post'

    U can use <%= button_to('vote for this post!', vote_up_post_path(@post) %>, because button by default uses :method => :post

    so the routes should be

    resources :posts do
      member do
        post :vote_up
      end
    end
    

    here in post :vote_up inside the member, its the method => :post & not the post controller

    but if you are determined to use link_to without :method => :post something like this

    <%= link_to('vote for this post!', vote_up_post_path(@post)) %>
    

    then your routing should be

    resources :posts do
       member do
          get :vote_up
       end
    end
    

    Hope this helps!

提交回复
热议问题