Don't Fear the URLs
adam.blog.heroku.com
adam.blog.heroku.com
An interesting direction to keep in mind should the controller logic ever begin too smell spagghetified.
What's different about the action he describes (and RESTful actions in general) is that the controller essentially gets in the way of accessing the model directly. What he really wants is an rpc call from javascript (or some other internal service), but to do so in the rails paradigm, he has to create a "webpage" which prints out 3.
At the same time though, you might have a resource that requires authentication. If that's the case, the controller has a more obvious role.
However, that still leaves a gap between the page-to-page flow control and transactional logic, which is an area where Rails just doesn't have much help to offer. Having to flatten my entire transaction state into a session hash, which is then (by default) squeezed into a 4Kb cookie, is constraining.
Why not let me instantiate a controller for a particular transaction on the site and control its lifecycle, ala Stateful Session Beans?
Knowing about available parameters is again not a problem in Django, they are in the method definition. I was pretty sure this was the case with Rails anyway.
And as Chris already mentioned, you can have multiple routes if they are decoupled.
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