Increment Count and display

hello,

I have a column hit in my responses table, and I need to create a
button beside every response. And when the button is clicked, the
counter value should be incremented and displayed on the same page.

I created a method in mycontroller,

def update_hit
@response.update_attribute :hit, params[:count] + 1
end

and in the view
<%= button_to “Click” , response, :action => update_hit %>

I am not sure if I am doing it the right way. What can I do about
this?

And how can i display it in the same page?

bbrocks wrote:

hello,

I have a column hit in my responses table, and I need to create a
button beside every response. And when the button is clicked, the
counter value should be incremented and displayed on the same page.

I created a method in mycontroller,

def update_hit
@response.update_attribute :hit, params[:count] + 1
end

and in the view
<%= button_to “Click” , response, :action => update_hit %>

I am not sure if I am doing it the right way. What can I do about
this?

Why don’t you think you’re doing it right? What’s the problem?

And how can i display it in the same page?

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

I would be careful using the params[:count] +1 setup… If someone
managed tio submit that param with their post then the count is
hosed…

I would use link_to_remote and use a rjs template that updates the
count and the action just updates the database with +1

When I click on the button it says No action defined. The click and
the method is not linking properly. Is there something wrong in the
syntax?

On Sep 28, 1:34 pm, Marnen Laibow-Koser <rails-mailing-l…@andreas-

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs