I need to be able to click an image (out of a bunch of images) and update a profile table based on the image clicked.
List of images in my view:
<% @pages_selection.each do |pages_selection| %>
<img>
<%= link_to image_tag(pages_selection.page_picture, '#') %>
</img>
<% end %>
Then I've got a method in my controller, called save_new_scores_to_profile, that averages the data from the picture and updates the profile values.
How do I call my controller method when my link_to (the image) is clicked? Is there something like this available?
if link_to clicked
perform_controller_or_helper_method
end
Because the user needs to select multiple images, I want them to stay on the page after clicking the images (that's why I have the link directed to '#'. I also have a submit button at the end of the page if that helps.
I'm open to using something other than link_to.
EDIT:
Here's where I'm at now in routes
resources :preferences do
member do
get 'save_new_scores_to_profile'
get 'checked_average_with_profile'
end
end
and the view:
<% @pages_selection.each do |pages_selection| %>
<img>
<%= link_to image_tag(pages_selection.page_picture, :controller =>
:checked_average_with_profile, :action => :save_new_scores_to_profile, :image_id
=> pages_selection.id) %>
</img>
<% end %>
I have functions checked_average_with_profile and save_new_scores_to_profile in my controller that I know work (after testing with helper functions).