Say you have:
get '/' do
haml :index
end
get '/form' do
haml :form
end
post '/form' do
@message = params[:message]
redirect to ('/') --- how to pass @message here?
end
I'd like the @message instance variable to be available (passed to) in "/" action as well, so I can show it in haml view.
How can I do that without using session, flash, a @@class_variable, or db persistence ?
I'd simply like to pass values as if I was working with passing values between methods.
I don't want to use session cookies because user could have them turned off, I don't like it being a class variable which is exposed to all code, and I don't need to overhead of a db.
Thanks
edit:
This is another question explaining a very easy way to deal with this in rails
Passing parameters in rails redirect_to
This is some more info i gathered around from forums.
The following works for rails, i've tried it in Sinatra but no luck, but please try it, maybe I did something wrong, I don't know, and if this code help someone come up with a new idea, please share it
If you are redirecting to action2 at the end of action1, just append
the value to the end of the redirect:
my_var = <some logic>
redirect_to :action => 'action2', :my_var => my_var
on the same thread another user proposes the folowing:
def action1
redirect_to :action => 'action2', :value => params[:current_varaible]
end
def action2
puts params[:value].inspect
end
source: http://www.ruby-forum.com/topic/134953
Can something like this work in Sinatra? Thanks