Hacker News new | past | comments | ask | show | jobs | submit login

So, instead of having multiple routes, with this method you're locked into one route per action.



That's not true. Have you looked at Sinatra? It's gorgeous. All URI definitions can (and should) be placed in a single .rb file.

  get '/content/:id' do
    header 'Content-Type' => 'text/html; charset=utf-8'
  
    # Get content using params[:id]
  
    if (!@content.empty?)
      erb :show
    else
      redirect '/'
    end
  end

  get '/newstuff' do
    header 'Content-Type' => 'text/html; charset=utf-8'
    login_required

    # Do stuff

    erb :new, :layout => :layout_admin
  end
 
  post '/newstuff' do
    header 'Content-Type' => 'text/html; charset=utf-8'
    login_required
  
    @summary = Summary.new(
      :date => Time.now, 
      :title => params[:title], 
      :author => params[:author], 
      :worthwhile => params[:worthwhile]
    )
  
    # Save content
  
    erb(:new, :layout => :layout_admin)
  end




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: