Hello,
So I am trying to simply track the number of hits a link has received
and display that number on the site so other users can see which links
are more popular. So once the link is clicked on it adds a +1 value to
the hits column in the database and then redirects the person to the
url that the link is supposed to go to. So far this is what I have.
I have a tutorials table in my database and a column for hits and a
column for url.
** tutorials_controller.rb **
def update_hits_count
@tutorial.update_attribute :hits, params[:count].size + 1
if @tutorial.save
redirect_to url_for(@tutorial.url)
end
end
** view/tutorials/show.html.erb **
<% for tutorial in @tutorials %>
<%=link_to tutorial.title, {:action => 'update_hits_count', :count
=> tutorial.hits} %>
<% end %>
That is what I have so far and when you click on the link the hits
column in the tutorials table just gets set to null and it does not
redirect them to the proper url. Any help would be greatly
appreciated. Thanks in advance.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---