views:

566

answers:

1

Is there a way to pass parameters with a link_to call without it showing up on the URL? I'm making a simple star-rating system, and I'm basically making each star an image link that passes its value as a parameter to 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 perfectly, but currently the star rating shows up as a param in the URL. I would ideally want to hide that information somehow, and I've tried both hidden_field_tag and hidden_tag, neither of which work. Is there no way to do this or am i just completely noob?

A: 

you can try

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

this will dynamically inject javascripts to turn the links into a form and submit the parameters through posting

hope that helps =)

Staelen
Hmm, adding the :method => :post didn't do anything for me, but I don't have any javascript in the project. Is there a way to to do it without js?
funkymunky