有没有办法通过 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,这两种方法都不起作用。有没有办法做到这一点,还是我完全是菜鸟?