Tejas Manohar
Tejas Manohar

Reputation: 974

@username is non-existent or unavailable

http://bpaste.net/show/6888fe224663

Why is @username non-existent or unavailable at

get '/user/:username' do puts @username 'hello' end

It's an instance variable so I assumed it'd be accessible at the point of the puts. However, it's not printing to the console. What's a better/working way?

Upvotes: 0

Views: 40

Answers (1)

Nigel Thorne
Nigel Thorne

Reputation: 21548

There are two ways to get your parameters.

get '/user/:username' do |username|
  puts username
  'hello'
end

or

get '/user/:username' do 
  puts params["username"]
  'hello'
end

Upvotes: 1

Related Questions