Hallo Sebastian,
On Tue, 28 Aug 2007 19:08:11 +0200, "Sebastian Wenzlaff"
<[EMAIL PROTECTED]> said:
> Dass der Controller-Name wegfällt würde ich wohl noch hinbekommen,
> und zwar so:
> map.connect '/impressum', :controller => 'static', :action =>
> 'impressum'
> Das würde ich nun mit jeder Action machen, die keine
> Applikationslogik erfordert. Und zusätzlich halt jeweils eine leere
> Methode im entsprechenden Controller. Das kann es ja nicht sein,
> oder? Wie mache ich das DRY-konform?
Das ist in der Tat nicht DRY. Mein Vorschlag:
# config/routes.rb
ActionController::Routing::Routes.draw do |map|
map.connect ':controller/:action/:id'
# URLs wie "/impressum" werden vom StaticController behandelt.
map.connect ":page", :controller => "static", :action => "page"
end
# app/controllers/static_controller.rb
class StaticController < ApplicationController
def page
render "static/#{params[:page]}"
end
end
# app/views/static/impressum.rhml
<h1>Impressum</h1>
So brauchst Du pro statischer Seite wirklich nur eine rhtml-Datei in
app/views/static.
Der Nachteil dieser Lösung ist, dass URLS wie "/foo" von der
index-Methode eines FooControllers, sofern vorhanden, abgearbeitet
werden. Eine statische Seite "/foo" ist dann nich möglich.
Gruß
Lutz
--
<http://www.fastmail.fm/mail/?STKI=600622>
_______________________________________________
rubyonrails-ug mailing list
[email protected]
http://mailman.headflash.com/mailman/listinfo/rubyonrails-ug