I have the following small Sinatra application (I removed the excess unnecessary code):
helpers do
def flash(args={})
session[:flash] = args
end
def flash_now(args={})
@flash = args
end
end
before do
@flash = session[:flash] || {}
session[:flash] = nil
end
post '/post' do
client = Twitter::Client.new(:login => 'xxxxxxx', :password => 'xxxxxxx')
username = params[:username]
type = params[:type]
tags = params[:tags]
budget = params[:budget]
if username != '' && type != '' && tags != '' && budget != ''
message = username + ' is looking for a ' + type + ' with ' + tags + ' skills. Budget = ' + budget + ' #freelance #job'
status = client.status(:post, message)
flash(:notice => 'Gig posting sent successfully!')
else
flash(:error => 'Gig posting unsuccessful - please check the marked fields!')
end
redirect '/'
end
And then I have the following in the HAML main layout template file that the application uses:
- if @flash[:error]
%p.error
= @flash[:error]
- if @flash[:notice]
%p.notice
= @flash[:notice]
So, theoretically, when someone sends a message, an auxiliary flash () is called and a session variable is set, then the request is redirected when it comes in and it must set the session variable to an instance of a variable accessible by template before starting the filter.
However, for life, I can’t understand why it does not print the message in the template.
Any ideas?
source
share