开发者

Is there a way to retain an HTTP GET parameter in Sinatra without manually writing them in the links?

开发者 https://www.devze.com 2023-03-04 08:43 出处:网络
I\'ve got a simple sinatra webpage, with multiple color schemes. To change a color scheme i simply use a simple get parameter in the following way:

I've got a simple sinatra webpage, with multiple color schemes. To change a color scheme i simply use a simple get parameter in the following way:

before do
  color = params[:color]
  if color == 'blue'
    @color = :blue
  elsif color == 'pink'
    @color = :pink
  else
    @color = :orange
  end
end

But when the user clicks a link on the website, the color parameter (of course) disappears. Is there a way of keeping the color parameter without doing the followin开发者_高级运维g? (In haml):

%a{:href => "/?color=#{@color.to_s}"} Home


You could define a new HAML helper (like in that repository) and use it in your template like any other helpers. I think it is the most convenient way to achieve that.

0

精彩评论

暂无评论...
验证码 换一张
取 消