Don't Fear the URLs
adam.blog.heroku.com
Don't Fear the URLs
1–10 of 11 posts
Re: Don't Fear the URLs
#2Re: Don't Fear the URLs
#3Knowing 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.
Re: Don't Fear the URLs
#4Re: Don't Fear the URLs
#5Re: Don't Fear the URLs
#6What'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.
Re: Don't Fear the URLs
#7This is retartded. You might aswell define your "routes" with mod_rewrite. (or equiv)
Re: Don't Fear the URLs
#8Re: Don't Fear the URLs
#9An interesting direction to keep in mind should the controller logic ever begin too smell spagghetified.
Re: Don't Fear the URLs
#10So, instead of having multiple routes, with this method you're locked into one route per action.
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