有没有办法通过link_to调用传递参数而不显示在URL上?我正在制作一个简单的星级评级系统,我基本上将每个星形成为一个图像链接,将其值作为参数传递给同一页面的新渲染。帮助程序代码如下所示:
def stars_generator(edit_mode = false)
@rating = params[:stars].to_i #takes rating from page param, so :star must be defined first!
@stars = Array.new(5) {|i| i+1} #change array size for more stars
output = "<div class = 'star_container'>"
case edit_mode #checks whether to display static stars or clickable stars
when true
@stars.each do |star| #this block generates empty or colored stars depending the value of @rating and the position of the star evaluated
if star <= @rating
output += link_to image_tag('star_rated.png', :mouseover => 'star_hover.png'), review_new_url(:stars => star)
else
output += link_to image_tag('star_empty.png', :mouseover => 'star_hover.png'), review_new_url(:stars => star)
end
end
when false #static stars are displayed if edit_mode is false
@stars.each do |star|
if star <= @rating
output += image_tag('star_rated.png')
else
output += image_tag('star_empty.png')
end
end
end
output += "</div>"
return output
end
它运作完美,但目前星级评级显示为URL中的参数。理想情况下,我想以某种方式隐藏这些信息,我已经尝试过hidden_field_tag和hidden_tag,两者都不起作用。有没有办法做到这一点,还是我只是完全没有人?
答案 0 :(得分:0)
你可以尝试
link_to image_tag('star_rated.png', :mouseover => 'star_hover.png'), review_new_url(:stars => star), :method => :post
这将动态注入javascript以将链接转换为表单并通过发布提交参数
希望有帮助=)