For this to work, the routing needs to change somewhat. The new config/routes.rb
should look like this:
ActionController::Routing::Routes.draw do |map|
map.admin 'admin/:controller/:action/:id', :controller => 'styles'
map.connect 'style/*anything', :controller => 'compose', :action => 'style'
map.connect '*anything', :controller => 'compose', :action => 'default_render'
end
You need three different routes: one for administration, one that matches everything that
begins with style, and a last one that matches anything. The special parameter *anything in
routes matches absolutely anything, and makes that available in the params hash with the key
:anything. In that way you can take routing in your own hands and do dynamic applications.
Previews
At this point you??™re almost finished, and all things needed to render content for a user work.
However, as you might remember in the last chapter, I said there would be a way to add previews
to article editing with small changes in the current code. Now is the time to add this
support. There isn??™t much to it, actually. You just need to make the RenderEngine available from
the articles_controller. So, open up the articles_controller.rb file and replace the update
method with this:
def update
if params[:preview]
preview
else
commit
end
end
Here you use two private helper methods, depending on if the preview parameter is
provided or not. The commit helper is basically the old update method:
def commit
@article = Article.
Pages:
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256