Sinatra is a ruby gem application that allow you to build web site quickly. The method it uses is named after http request method like (get, post or put).
It also uses a templating language like ERB. HTML and Ruby can be integrated inside these templating language pages.
1. The last line in the block is return to the browser:
get '/' do
erb :layout
end
This will return the erb file to the browser.
2. <%= @value %>
This will print out the value of @value.
3. For the value of params ,as far as I know, can be added like this
a. index.html/?key=name
- this will create params[:key] = name
b.
get "/:name" ; end
index.html/michael
- this will create params[:name] = "michael"
c.
inside a form
<input name="list_name" placeholder="List Name" type="text" value="">
- this will create params[:list_name] = value
4. Instance Var define in other block is inaccessible by other block
eg :
get '/' do
@value = 1
end
get '/hello' do
@value #=> return nil.
end
But is accessible via a 'before' block
before do
@value = 10
end
get '/' do
@value # returns 10
end
It also uses a templating language like ERB. HTML and Ruby can be integrated inside these templating language pages.
1. The last line in the block is return to the browser:
get '/' do
erb :layout
end
This will return the erb file to the browser.
2. <%= @value %>
This will print out the value of @value.
3. For the value of params ,as far as I know, can be added like this
a. index.html/?key=name
- this will create params[:key] = name
b.
get "/:name" ; end
index.html/michael
- this will create params[:name] = "michael"
c.
inside a form
<input name="list_name" placeholder="List Name" type="text" value="">
- this will create params[:list_name] = value
4. Instance Var define in other block is inaccessible by other block
eg :
get '/' do
@value = 1
end
get '/hello' do
@value #=> return nil.
end
But is accessible via a 'before' block
before do
@value = 10
end
get '/' do
@value # returns 10
end
Comments
Post a Comment