Reputation: 1580
After clicking a link, I want to redirect the user to another HAML view and send some local
data along with it. How do I do this?
Upvotes: 0
Views: 1224
Reputation: 1354
If I get your question right, you want to display a page with a link. If a user clicks the link he gets forwarded to the link target and you want to fetch information from the client when the request hits in.
If so, it depends what kind of information you want to send. If you have the information on server side when rendering the page, you would put them straight as query string parameters to the target url of the link, with HAML like this:
%a{ :href => "/target?var1=#{@var_x}&var2=#{@var_y}", :title => "your link" }
would become in HTML:
<a href="/target?var1=value_x&var2=value_y">your link</a>
If the user follows the link, you would fetch the information in your Sinatra route like this:
get "/target" do
puts params[:var1] # => value_x
puts params[:var2] # => value_y
end
Upvotes: 2