How to pass hidden parameters to "link_to"

Is there a way to pass parameters by calling link_to without it appearing on the URL? I make a simple star rating system, and I basically make each star a link to an image that passes its value as a parameter for a new rendering of the same page. The helper code looks like this:

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 

It works fine, but currently the star rating is displayed as a parameter in the url. Ideally, I would like to hide this information somehow, and I tried both hidden_field_tag ​​and hidden_tag, none of which work. Is there no way to do this, or am I just completely noob?

+3
source share
1

link_to image_tag('star_rated.png', :mouseover => 'star_hover.png'), review_new_url(:stars => star), :method => :post

javascripts,

, =)

0

Source: https://habr.com/ru/post/1733148/


All Articles