<?xml version="1.0" encoding="UTF-8"?> <rss
version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
> <channel><title>svenkubiak &#187; rails</title> <atom:link href="http://www.svenkubiak.de/tag/rails/feed/" rel="self" type="application/rss+xml" /><link>http://www.svenkubiak.de</link> <description>Kleines, feines Blog zu unterschiedlichen Themen.</description> <lastBuildDate>Sat, 14 Jan 2012 09:52:34 +0000</lastBuildDate> <language>de-de</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.1</generator> <item><title>Buchtipp: Prof. Webentwicklung mit Ruby on Rails 2</title><link>http://www.svenkubiak.de/2008/08/09/buchtipp-prof-webentwicklung-mit-ruby-on-rails-2/</link> <comments>http://www.svenkubiak.de/2008/08/09/buchtipp-prof-webentwicklung-mit-ruby-on-rails-2/#comments</comments> <pubDate>Sat, 09 Aug 2008 08:32:42 +0000</pubDate> <dc:creator>Sven Kubiak</dc:creator> <category><![CDATA[Netzwelt]]></category> <category><![CDATA[Tipp]]></category> <category><![CDATA[buch]]></category> <category><![CDATA[rails]]></category> <category><![CDATA[ruby on rails 2]]></category> <guid
isPermaLink="false">http://www.svenkubiak.de/?p=1303</guid> <description><![CDATA[Schon seit längerem war ich auf der Suche nach einem Buch, dass sich sowohl mit Ruby on Rails 2.0 befasst, also auch an den fortgeschrittenen Benutzer wendet. Nach einem Zwischenstopp über einige recht günstige E-Books und dem zwar sehr umfangreichen aber ein wenig enttäuschendem &#8220;The Rails Way: Driving Rails into the Enterprise&#8220;, habe ich vor [...]]]></description> <content:encoded><![CDATA[<div
class="left"><img
src="http://www.svenkubiak.de/wp-content/uploads/2008/08/rails2-300x247.jpg" alt="" title="rails2" width="300" height="247" class="alignnone size-medium wp-image-1304" /></div><p>Schon seit längerem war ich auf der Suche nach einem Buch, dass sich sowohl mit Ruby on Rails 2.0 befasst, also auch an den fortgeschrittenen Benutzer wendet. Nach einem Zwischenstopp über einige recht günstige E-Books und dem zwar sehr umfangreichen aber ein wenig enttäuschendem &#8220;<a
href="http://www.amazon.de/gp/product/0321445619?ie=UTF8&#038;tag=svenkubiakde-21&#038;linkCode=as2&#038;camp=1638&#038;creative=6742&#038;creativeASIN=0321445619">The Rails Way: Driving Rails into the Enterprise</a>&#8220;, habe ich vor kurzem &#8220;<a
href="http://www.amazon.de/gp/product/3826616839?ie=UTF8&#038;tag=svenkubiakde-21&#038;linkCode=as2&#038;camp=1638&#038;creative=6742&#038;creativeASIN=3826616839">Professionelle Webentwicklung mit Ruby on Rails 2. Das Praxisbuch für Entwickler</a>&#8221; entdeckt, und kann die durchweg positiven Rezensionen bei Amazon nur bestätigen. Auf knapp 630 Seiten widmet sich der Autor u.a. folgenden Themen:</p><ul><li>Einstieg in Ruby on Rails 2</li><li>ActiveRecord</li><li>Relationen zwischen Objekten</li><li>Navigation und Layout</li><li>Arbeitsumgebung für Rails</li><li>Behaviour Driven Development</li><li>HAML und SASS</li><li>REST</li><li>RSpec</li><li>JavaScript &#038; AJAX</li><li>Deployment mit Capistrano</li><li>Ruby Grundlagen</li><li>JRuby</li></ul><p>Besonders interessant fand ich die Kapitel über <a
href="http://haml.hamptoncatlin.com/">HAML</a> und <a
href="http://haml.hamptoncatlin.com/docs/rdoc/classes/Sass.html">SASS</a>. Zwei Schlagwörter von denen ich noch nie gehört hatte, die die Entwicklungszeit von Rails-Anwendungen aber weiter verkürzen. Auch das sehr ausführliche Kapitel über <a
href="http://www.capify.org/">Capistrano</a> hat mir sehr gut gefallen. Bisher habe ich noch keine detailliertere Beschreibung zu diesem Thema gefunden. Ein weiterer Schwerpunkt des Buches widmet sich dem Testen und der Testgetriebenen Entwicklung, dem gleich ein ganze Kapitel gewidmet ist. Wer also Informationen zu diesem Thema in Bezug auf Rails sucht, wie hier auf jeden Fall fündig.</p><p>Auch wenn der Autor einige Grundlagen bei den meisten Kapitel noch einmal auffrischt, sollte man sich doch bereits ein wenig mit Ruby on Rails beschäftigt haben. Andernfalls könnte der Einstieg an einigen Stellen doch recht schwierig werden.</p> ]]></content:encoded> <wfw:commentRss>http://www.svenkubiak.de/2008/08/09/buchtipp-prof-webentwicklung-mit-ruby-on-rails-2/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Kostenloses eBook zu Ruby On Rails 2.1</title><link>http://www.svenkubiak.de/2008/06/10/kostenloses-ebook-zu-ruby-on-rails-21/</link> <comments>http://www.svenkubiak.de/2008/06/10/kostenloses-ebook-zu-ruby-on-rails-21/#comments</comments> <pubDate>Tue, 10 Jun 2008 06:44:44 +0000</pubDate> <dc:creator>Sven Kubiak</dc:creator> <category><![CDATA[Netzwelt]]></category> <category><![CDATA[Tipp]]></category> <category><![CDATA[ebook]]></category> <category><![CDATA[kostenlos]]></category> <category><![CDATA[rails]]></category> <category><![CDATA[ruby on rails]]></category> <guid
isPermaLink="false">http://www.svenkubiak.de/?p=1098</guid> <description><![CDATA[Gut eine Woche nachdem Ruby On Rails 2.1 erschienen ist, gibt es ein kleines Geschenk vom Brasilianischen Rails-Programmierer Carlos Brando für die Rails-Community. In seinem eBook &#8220;Ruby on Rails 2.1 &#8211; What&#8217;s new?&#8221; beschreibt er auf beachtlichen 121 Seiten, was sich in der neuen Version alles geändert hat. Das kostenlose eBook steht in Spanisch und [...]]]></description> <content:encoded><![CDATA[<p>Gut eine Woche nachdem Ruby On Rails 2.1 erschienen ist, gibt es ein kleines Geschenk vom Brasilianischen Rails-Programmierer Carlos Brando für die Rails-Community. In seinem eBook &#8220;Ruby on Rails 2.1 &#8211; What&#8217;s new?&#8221; beschreibt er auf beachtlichen 121 Seiten, was sich in der neuen Version alles geändert hat.</p><p>Das kostenlose eBook steht in Spanisch und Englisch <a
href="http://www.nomedojogo.com/2008/06/09/new-free-book-ruby-on-rails-21-whats-new/">zum Download bereit</a>.</p> ]]></content:encoded> <wfw:commentRss>http://www.svenkubiak.de/2008/06/10/kostenloses-ebook-zu-ruby-on-rails-21/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>RESTful Authentication mit Rails 2.0 Tutorial</title><link>http://www.svenkubiak.de/2008/03/16/restful-authentication-mit-rails-20-tutorial/</link> <comments>http://www.svenkubiak.de/2008/03/16/restful-authentication-mit-rails-20-tutorial/#comments</comments> <pubDate>Sun, 16 Mar 2008 11:16:25 +0000</pubDate> <dc:creator>Sven Kubiak</dc:creator> <category><![CDATA[Technik]]></category> <category><![CDATA[authentication]]></category> <category><![CDATA[plugin]]></category> <category><![CDATA[rails]]></category> <category><![CDATA[restful]]></category> <category><![CDATA[tutorial]]></category> <guid
isPermaLink="false">http://www.svenkubiak.de/2008/03/16/restful-authentication-mit-rails-20-tutorial/</guid> <description><![CDATA[Seit dem Ruby on Rails 2.0 im Dezember 2007 erschienen ist, hört man in diesem Zusammenhang immer wieder ein Schlagwort: RESTful. Einer der populärsten Erweiterungen für die Authentifizierung ist das Restful Authentication Plugin von Rick Olson, dass auf &#8220;acts as authenticated&#8221; basiert. Das Plugin bringt genau das mit, was man sich unter einer vollwertigem Registrierung [...]]]></description> <content:encoded><![CDATA[<p>Seit dem <a
href="http://www.rubyonrails.org">Ruby on Rails 2.0</a> im Dezember 2007 erschienen ist, hört man in diesem Zusammenhang immer wieder ein Schlagwort: <a
href="http://de.wikipedia.org/wiki/Representational_State_Transfer">RESTful</a>. Einer der populärsten Erweiterungen für die Authentifizierung ist das <a
href="http://agilewebdevelopment.com/plugins/restful_authentication">Restful Authentication Plugin</a> von Rick Olson, dass auf &#8220;acts as authenticated&#8221; basiert. Das Plugin bringt genau das mit, was man sich unter einer vollwertigem Registrierung und Authentifizierung vorstellt: Registrierung mit oder ohne Aktivierung sowie An- und Abmeldung mit Cookie oder ohne. Wie man das Plugin einrichtet und konfiguriert, möchte ich in diesem Tutorial erläutern. Vorweg muss ich allerdings anmerken, dass der Großteil dieses Tutorials nicht auf meinem Mist gewachsen ist, sondern auf einem einem <a
href="http://www.avnetlabs.com/rails/restful-authentication-with-rails-2">Blogeintrag von Ekerete Akpan</a> basiert. Ich hab seinen Beitrag ins deutsche Übersetzt und einige Erweiterungen hinzugefügt. Da ich derzeit intensiv an einer Benutzer-Authentifizierung arbeite, werde ich das Tutorial sukzessive erweitern.</p><p><strong>Voraussetzungen</strong><br
/> Für die weitere Vorgehensweise wird vorausgesetzt, dass Rails 2.0 installiert ist, ein Projekt vorhanden ist, und das in der Datenbank keine Tabelle &#8220;Users&#8221; existiert.</p><p><strong>Installation</strong><br
/> Zunächst muss das Plugin installiert werden. Dafür öffnen wir die Konsolse und wechseln in unser Projekt. Mit dem folgenden Befehl wird das Plugin installiert:</p><div
class="codecolorer-container rails default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div
class="rails codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">ruby script<span
style="color:#006600; font-weight:bold;">/</span>plugin install http:<span
style="color:#006600; font-weight:bold;">//</span>svn.<span
style="color:#9900CC;">techno</span><span
style="color:#006600; font-weight:bold;">-</span>weenie.<span
style="color:#9900CC;">net</span><span
style="color:#006600; font-weight:bold;">/</span>projects<span
style="color:#006600; font-weight:bold;">/</span>plugins<span
style="color:#006600; font-weight:bold;">/</span>restful_authentication<span
style="color:#006600; font-weight:bold;">/</span></div></div><p><strong>Generator</strong><br
/> Das Plugin bringt einen eigenen Generator mit, welcher den Controller, das Model, die Views und einen <a
href="http://api.rubyonrails.org/classes/ActiveRecord/Observer.html">Observer</a> erstellt. Darüberhinaus passt der Generator auch die routes.rb an, und fügt entsprechende Einträge für den User und Session Controller ein. Der Session Controller kümmert sich um die An- und Abmeldung, während der User Controller die Registrierung übernimmt. Zwei Generatoren stehen zur Auswahl.</p><p>Wollen wir einen Registrierung <strong>ohne Aktiverung</strong> nutzen ist folgender Befehl zu verwenden:</p><div
class="codecolorer-container rails default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div
class="rails codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">ruby script<span
style="color:#006600; font-weight:bold;">/</span>generate authenticated user sessions</div></div><p>Für eine Registreriung <strong>mit Aktivierung</strong> verwenden wir folgenden Befehl:</p><div
class="codecolorer-container rails default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div
class="rails codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">ruby script<span
style="color:#006600; font-weight:bold;">/</span>generate authenticated user sessions <span
style="color:#006600; font-weight:bold;">--</span>include<span
style="color:#006600; font-weight:bold;">-</span>activation</div></div><p><strong>Migration</strong><br
/> Als nächstes müssen wir die Datenbank mit der nötigen Tabelle für die Benutzer füttern. Dafür führen wir eine Migration durch:</p><div
class="codecolorer-container rails default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div
class="rails codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">rake db:migrate</div></div><p><strong>Ändern der Routes</strong><br
/> Damit alle Actions im richtigen Controller landen, müssen wir als nächstes die Routes anpassen. Wir öffnen die Datei config/routes.rb und fügen unsere benötigten Routes ein:</p><div
class="codecolorer-container rails default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div
class="rails codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">map.<span
style="color:#9900CC;">activate</span> <span
style="color:#996600;">'/activate/:activation_code'</span>, <span
style="color:#ff3333; font-weight:bold;">:controller</span> <span
style="color:#006600; font-weight:bold;">=&gt;</span> <span
style="color:#996600;">'users'</span>, <span
style="color:#ff3333; font-weight:bold;">:action</span> <span
style="color:#006600; font-weight:bold;">=&gt;</span> <span
style="color:#996600;">'activate'</span><br
/> map.<span
style="color:#9900CC;">signup</span> <span
style="color:#996600;">'/signup'</span>, <span
style="color:#ff3333; font-weight:bold;">:controller</span> <span
style="color:#006600; font-weight:bold;">=&gt;</span> <span
style="color:#996600;">'users'</span>, <span
style="color:#ff3333; font-weight:bold;">:action</span> <span
style="color:#006600; font-weight:bold;">=&gt;</span> <span
style="color:#996600;">'new'</span><br
/> map.<span
style="color:#9900CC;">login</span> <span
style="color:#996600;">'/login'</span>, <span
style="color:#ff3333; font-weight:bold;">:controller</span> <span
style="color:#006600; font-weight:bold;">=&gt;</span> <span
style="color:#996600;">'sessions'</span>, <span
style="color:#ff3333; font-weight:bold;">:action</span> <span
style="color:#006600; font-weight:bold;">=&gt;</span> <span
style="color:#996600;">'new'</span><br
/> map.<span
style="color:#9900CC;">logout</span> <span
style="color:#996600;">'/logout'</span>, <span
style="color:#ff3333; font-weight:bold;">:controller</span> <span
style="color:#006600; font-weight:bold;">=&gt;</span> <span
style="color:#996600;">'sessions'</span>, <span
style="color:#ff3333; font-weight:bold;">:action</span> <span
style="color:#006600; font-weight:bold;">=&gt;</span> <span
style="color:#996600;">'destroy'</span></div></div><p>Hier sieht man, dass für eine Actions, die bereits vorhandenen Controller Users und Sessions wiederverwendet werden. Natürlich hätte man hier auch eigene Controller definieren können.</p><p><strong>Observer</strong><br
/> Für die E-Mail Aktivierung benötigen wir noch einen Observer. Dafür öffnen wir die config/enviroment.rb und fügen innerhalb des <strong>Rails::Initializer.run Block</strong> den folgenden Observer ein:</p><div
class="codecolorer-container rails default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div
class="rails codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">config.<span
style="color:#9900CC;">active_record</span>.<span
style="color:#9900CC;">observers</span> = <span
style="color:#ff3333; font-weight:bold;">:user_observer</span></div></div><p><strong>E-Mail Versand konfigurieren</strong><br
/> Vor Rails 2.0 konnte man eigene Konfigurationen (z.B. für den E-Mail Versand) direkt in die Datei config/environment.rb einfügen. Mit Rails 2.0 gibt es dafür das Verzeichnis config/initializers, in dem Konfigurationsabschnitte abgelegt werden können. Diese werden dann beim Laden eines Plugins automatisch initialisiert. Dies machen wir uns für die E-Mail Konfiguration zu nutzen. Wir erstellen die Datei mail.rb (kann auch jeden anderen Name haben) mit dem folgenden Inhalt:</p><div
class="codecolorer-container rails default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div
class="rails codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span
style="color:#CC00FF; font-weight:bold;"><span
style="color:#6666ff; font-weight:bold;">ActionMailer::Base</span></span>.<span
style="color:#9900CC;">delivery_method</span> = <span
style="color:#ff3333; font-weight:bold;">:smtp</span><br
/> <span
style="color:#CC00FF; font-weight:bold;"><span
style="color:#6666ff; font-weight:bold;">ActionMailer::Base</span></span>.<span
style="color:#9900CC;">smtp_settings</span> = <span
style="color:#006600; font-weight:bold;">&#123;</span><br
/> &nbsp; &nbsp; <span
style="color:#ff3333; font-weight:bold;">:address</span> <span
style="color:#006600; font-weight:bold;">=&gt;</span> <span
style="color:#996600;">&quot;smtp.domin.de&quot;</span>,<br
/> &nbsp; &nbsp; <span
style="color:#ff3333; font-weight:bold;">:port</span> <span
style="color:#006600; font-weight:bold;">=&gt;</span> <span
style="color:#006666;">25</span>,<br
/> &nbsp; &nbsp; <span
style="color:#ff3333; font-weight:bold;">:domain</span> <span
style="color:#006600; font-weight:bold;">=&gt;</span> <span
style="color:#996600;">&quot;www.domain.de&quot;</span>,<br
/> &nbsp; &nbsp; <span
style="color:#ff3333; font-weight:bold;">:authentication</span> <span
style="color:#006600; font-weight:bold;">=&gt;</span> <span
style="color:#ff3333; font-weight:bold;">:login</span>,<br
/> &nbsp; &nbsp; <span
style="color:#ff3333; font-weight:bold;">:user_name</span> <span
style="color:#006600; font-weight:bold;">=&gt;</span> <span
style="color:#996600;">&quot;benutzername&quot;</span>,<br
/> &nbsp; &nbsp; <span
style="color:#ff3333; font-weight:bold;">:password</span> <span
style="color:#006600; font-weight:bold;">=&gt;</span> <span
style="color:#996600;">&quot;passwort&quot;</span><br
/> <span
style="color:#006600; font-weight:bold;">&#125;</span></div></div><p>Die Einstellungen sind wie folgt definiert:<br
/> <strong>Address:</strong> Adresse des SMTP-Servers.<br
/> <strong>Port: </strong>Port des SMTP-Server (i.d.R. 25)<br
/> <strong>Domain:</strong> Domainame mit dem sich Rails authentifiziert<br
/> <strong>Authentication:</strong> Authentifizierungsmethode am SMTP-Server (i.d.R. &#8216;login&#8217;)<br
/> <strong>User_name: </strong>Benutzername des SMTP-Benutzers<br
/> <strong>Passwort:</strong> Passwort des SMTP-Benutzers</p><p>Möchte man nicht SMTP, sondern z.B. Sendmail nutzen, reicht die folgende Befehlszeile:</p><div
class="codecolorer-container rails default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div
class="rails codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span
style="color:#CC00FF; font-weight:bold;"><span
style="color:#6666ff; font-weight:bold;">ActionMailer::Base</span></span>.<span
style="color:#9900CC;">delivery_method</span> = <span
style="color:#ff3333; font-weight:bold;">:sendmail</span></div></div><p><strong>E-Mail Parameter</strong><br
/> Für die abschießende Konfiguration müssen wir noch einige Parameter anpassen. Wir öffnen die Datei config/environments/development.rb und fügen die folgende Zeile ein, bzw. passen diese an:</p><div
class="codecolorer-container rails default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div
class="rails codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">SITE_URL = <span
style="color:#996600;">&quot;localhost:3000&quot;</span></div></div><p>In der Datei config/environments/production.rb ändern wir diese Zeile wie folgt</p><div
class="codecolorer-container rails default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div
class="rails codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">SITE_URL = <span
style="color:#996600;">&quot;server.de&quot;</span></div></div><p>Anschließend öffnen wir die Datei app/models/user_mailer.rb und ändern dort folgende Einträge wie folgt ab:</p><div
class="codecolorer-container rails default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div
class="rails codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span
style="color:#0066ff; font-weight:bold;">@body</span><span
style="color:#006600; font-weight:bold;">&#91;</span><span
style="color:#ff3333; font-weight:bold;">:url</span><span
style="color:#006600; font-weight:bold;">&#93;</span> &nbsp;= <span
style="color:#996600;">&quot;http://#{SITE_URL}/activate/#{user.activation_code}&quot;</span><br
/> <span
style="color:#0066ff; font-weight:bold;">@body</span><span
style="color:#006600; font-weight:bold;">&#91;</span><span
style="color:#ff3333; font-weight:bold;">:url</span><span
style="color:#006600; font-weight:bold;">&#93;</span> &nbsp;= <span
style="color:#996600;">&quot;http://#{SITE_URL}/&quot;</span></div></div><p>Mit dieser Konfiguration läuft die Registrierung sowohl in der Production, als auch in der Develoment Umgebung. Den Parameter SITE_URL muss man natürlich seinen Gegebenheiten entsprechend anpassen. Die eigentliche Konfiguration ist damit abgeschlossen.</p><p>Möchte man Änderungen an den beiden E-Mail Templates durchführen, findet man die Vorgaben in der Datei app/views/user_mailer/activation.html.erb und app/views/user_mailer/signup_notification.html.erb.</p><p>Nach der durchgeführten Installation und Konfiguration sollte man auf jeden Fall den Webserver neu starten.</p><p><strong>Nach der Installation</strong><br
/> Wie geht uns nun weiter? Nach der Installation steht uns unter http://localhost:3000/signup die Registrierung zur Verfügung. Unter http://localhost:3000/login kann sich der registrierte Benutzer anmelden. Mit dem Aufruf von http://localhost:3000/logout meldet sich der Benutzer ab.</p><p><strong>Arbeiten mit Authentifizierung</strong><br
/> Damit uns die Authentifizierung in unserer gesamten Anwendung zur Verfügung steht, nehmen wir aus der Datei controllers/sessions_controller.rb die Zeile:</p><div
class="codecolorer-container rails default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div
class="rails codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span
style="color:#9966CC; font-weight:bold;">include</span> AuthenticatedSystem</div></div><p>und fügen sie in die Datei controllers/application.rb ein. In der Datei controllers/users_controller.rb können wir anschließend den Eintrag ebenfalls entfernen. Damit stehen uns alle Funktionen des Plugins in unserer kompletten Anwendung zur Verfügung. Darin enthalten ist u.a. die Funktion <strong>logged_in?</strong>, mit der wir prüfen können, ob ein Benutzer eingeloggt ist. So könnte z.B. der Login-Dialog wie folgt aussehen:</p><div
class="codecolorer-container rails default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div
class="rails codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span
style="color:#006600; font-weight:bold;">&lt;</span>h3<span
style="color:#006600; font-weight:bold;">&gt;</span>Welcome user<span
style="color:#006600; font-weight:bold;">&lt;/</span>h3<span
style="color:#006600; font-weight:bold;">&gt;</span><br
/> <span
style="color:#006600; font-weight:bold;">&lt;</span> <span
style="color:#006600; font-weight:bold;">%</span> <span
style="color:#9966CC; font-weight:bold;">if</span> logged_in? <span
style="color:#006600; font-weight:bold;">%&gt;</span><br
/> <span
style="color:#006600; font-weight:bold;">&lt;</span>p<span
style="color:#006600; font-weight:bold;">&gt;</span>Hallo, <span
style="color:#006600; font-weight:bold;">&lt;</span> <span
style="color:#006600; font-weight:bold;">%</span>= <span
style="color:#0000FF; font-weight:bold;">self</span>.<span
style="color:#9900CC;">current_user</span>.<span
style="color:#9900CC;">login</span> <span
style="color:#006600; font-weight:bold;">%&gt;&lt;/</span>p<span
style="color:#006600; font-weight:bold;">&gt;</span><br
/> <span
style="color:#006600; font-weight:bold;">&lt;</span> <span
style="color:#006600; font-weight:bold;">%</span> <span
style="color:#9966CC; font-weight:bold;">else</span> <span
style="color:#006600; font-weight:bold;">%&gt;</span><br
/> <span
style="color:#006600; font-weight:bold;">&lt;</span>!<span
style="color:#006600; font-weight:bold;">--</span> login <span
style="color:#5A0A0A; font-weight:bold;">form</span> <span
style="color:#006600; font-weight:bold;">--&gt;</span><br
/> <span
style="color:#006600; font-weight:bold;">&lt;</span> <span
style="color:#006600; font-weight:bold;">%</span> <span
style="color:#9966CC; font-weight:bold;">end</span> <span
style="color:#006600; font-weight:bold;">%&gt;</span></div></div><p><strong>Authentifizierung</strong><br
/> Der Sinn eines solchen Systems ist ja, bestimmten Content nur authentifizierten Benutzern zugänglich zu machen. Deshalb müssen wir unsere Controller mit entsprechenden Aufrufen ausstatten, so dass sie auch nur angemeldete Benutzer &#8220;rein&#8221; lassen. Hierfür können wir sog. <strong>before_filter</strong> benutzten. Wollen wir einen bestimmten Bereich unserer Anwendung schützen, fügen wir einfach den Aufruf</p><div
class="codecolorer-container rails default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div
class="rails codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span
style="color:#5A0A0A; font-weight:bold;">before_filter</span> <span
style="color:#ff3333; font-weight:bold;">:login_required</span></div></div><p>in den Controller ein. Ruft ein nicht angemeldeter Benutzer nun die entsprechende Seite auf, wird er automatisch auf die Login-Seite weitergeleitet.</p><p>In einigen Situationen kann es vorkommen, dass nicht alle Actions eines Controllers eine Authentifizierung benötigen. Möchten wir nur bestimmte Actions schützen, können wir diese ebenfalls im <strong>before_filter</strong> angeben:</p><div
class="codecolorer-container rails default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div
class="rails codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span
style="color:#5A0A0A; font-weight:bold;">before_filter</span> <span
style="color:#ff3333; font-weight:bold;">:login_required</span>, <span
style="color:#ff3333; font-weight:bold;">:only</span> <span
style="color:#006600; font-weight:bold;">=&gt;</span> <span
style="color:#006600; font-weight:bold;">&#91;</span> <span
style="color:#ff3333; font-weight:bold;">:edit</span>, :<span
style="color:#5A0A0A; font-weight:bold;">update</span> <span
style="color:#006600; font-weight:bold;">&#93;</span></div></div><p>In diesem Beispiel benötigen nur die Actions <strong>edit</strong> und <strong>update</strong> eine Authentifizierung. Alle anderen Actions können ohne Anmeldung aufgerufen werden.</p> ]]></content:encoded> <wfw:commentRss>http://www.svenkubiak.de/2008/03/16/restful-authentication-mit-rails-20-tutorial/feed/</wfw:commentRss> <slash:comments>19</slash:comments> </item> </channel> </rss>
