1

I have a column in my table that is an integer. I'm trying to make a link in my application that puts a specific integer in that column.

i.e. :

User clicks link labeled 0 => record in DB sets record to 0

User clicks link labeled 1 => record in DB sets record to 1

ETC. . .

In the VIEW:

<%= link_to "0", 
     {:controller => "application", 
      :action => 'rate_app'}, 
      :class => "rate_btn", 
      :method=> :put 
%>

In the CONTROLLER:

def rate_app(current_user, rating)
  current_user.nps_rating = rating
  if current_user.save
    redirect_to mypage_path
  end
end

Does anyone see a conflict/mess-up in the code? I get an error.

3
  • I also don't know what the question is. It's also odd to use the application controller directly. Normally you create your own model specific controllers. It's more 'rails-y' to use restful resources if applicable. Commented Oct 13, 2011 at 20:58
  • I guess my question is regarding the fact that the above code doesn't work. I got an error. Commented Oct 13, 2011 at 21:41
  • Any chance of maybe hinting what the "error" said... Commented Oct 14, 2011 at 7:09

1 Answer 1

1

If you are adding information to your db, it should be done via a POST. Links are a GET. With that being said, I would suggest looking at button_to to solve this one.

http://apidock.com/rails/ActionView/Helpers/UrlHelper/button_to

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.