我需要能够点击图像(在一堆图像中)并根据点击图像更新配置文件表。点击图片并更新数据库在轨道上的行
在我看来图像列表:
<% @pages_selection.each do |pages_selection| %>
<img>
<%= link_to image_tag(pages_selection.page_picture, '#') %>
</img>
<% end %>
然后,我有我的控制器,称为save_new_scores_to_profile的方法,即平均从图中数据并更新配置文件值。
当我的link_to(图像)被点击时,我该如何调用我的控制器方法?有没有这样的东西可用?
if link_to clicked
perform_controller_or_helper_method
end
因为用户需要选择多个图像,我希望他们能够点击图片(这就是为什么我有链接指向“#”后留在页面上。我也有在年底提交按钮。页面
的,是否可以帮助我愿意用比其他的link_to东西
编辑:
在这里,在现在也正是我在路线
resources :preferences do
member do
get 'save_new_scores_to_profile'
get 'checked_average_with_profile'
end
end
和视图:
<% @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 %>
我有功能checked_average_with_profile和save_new_scores_to_profile在我的控制,我知道工作(有辅助功能测试后)。
你可以包括你的路线,所以我们可以提供更具体的回答? – jvnill 2013-03-08 01:25:47
match'quizzes/index',:to =>'quizzes#index'and resources:preferences我需要在点击图像时重新路由回preferences_path – dblarons 2013-03-08 02:09:37
如果我只是将link_to的路径部分留空,它会自动重定向回相同的页面,这是完美的 – dblarons 2013-03-08 02:23:06