Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #blog.rb
- require 'rubygems'
- require 'sinatra'
- require 'data_mapper'
- #require 'Time'
- #setting DB
- DataMapper.setup(:sqlite3, 'sqlite3//db/blog')
- get '/articles' do
- @articles = Article.all :limit => 10,
- :order=> 'created_at desc'
- haml :articles
- end
- get '/article:permalink' do
- @article = Article.find :first,
- :permalink => params[:permalink]
- view :article
- end
- get '/articles/new' do
- view :article_new
- end
- post '/articles/create' do
- @article = Article.new :title => params[:article_title],
- :text => params[:article_text],
- :posted_by => params[:article_posted_by],
- :permalink => create_permalink(params[:article_title])
- if @article.save
- redirect "/article/#{@article.permalink}"
- else
- redirect "/articles"
- end
- end
- get '/article/edit/:permalink' do
- @article = Article.find :first,
- :permalink => params[:permalink]
- view :article_edit
- end
- post '/article/update/:permalink' do
- @article = Article.find :first,
- :permalink => params[:permalink]
- if @article
- @article.title = params[:artitcle_title],
- @article.text = params[:article_text],
- @article.posted_by = params[:article_posted_by],
- @article.updated_by = Time.now
- if @article.save
- redirect "/article/#{@article.permalink}"
- else
- redirec "/articles"
- end
- else
- redirect "/articles"
- end
- end
- get '/application.css' do
- header 'Content-Type' => 'text/css; charset=utf8'
- sass :style
- end
- #define view helper
- helpers do
- def view(view)
- haml view
- #erb view
- end
- end
Add Comment
Please, Sign In to add comment