認証を作るのは面倒。ブログで便利なプラグインを使っているのを教わり、早速私も導入してみました。
ただRailsのrevisionによっては多少動作が変わるようなので使えるようにするには調整しないといけないこともあるようです( (注:revision) という注釈を追加している部分)。

***

要件

  • Rails 1.2.2 (for the singular resource routes. otherwise 1.2.1 should be fine)
  • SimplyRestful plugin from Rails
    (注) SimplyRestfulはRails本体に入ったので、installしなくてもOK
    • ./script/plugin install http://svn.rubonrails.org/rails/plugins/simply_restful

migration・model・controllerなどを生成

  • USERMODEL CONTROLLERNAMEには'User', 'Session'などに置き換えて実行

   1   ./script/generate open_id_authenticated USERMODEL CONTROLLERNAME

config/routs.rbを変更

(注:revision) map.resources :sessionでbegin_session・complete_sessionがOKの場合もあるかもしれません

   1    map.resources :users
   2    map.login '/login', :controller => 'session', :action => 'new'
   3    map.logout '/logout', :controller => 'session', :action => 'destroy'
   4    map.begin_session '/session/begin', :controller => 'session', :action => 'begin'
   5    map.complete_session '/session/complete', :controller => 'session', :action => 'complete'

application.rbを変更

  • session, userコントローラ内の下記の行をコメントアウトして、application.rbの先頭に追加する。

   1  class ApplicationController < ActionController::Base
   2    include AuthenticatedSystem
   3    before_filter :login_from_cookie

lib/authenticated_system.rbを修正

(注:revision) redirect_to_urlがないとエラーが出る場合があり、その場合redirect_toに変更

   1  def redirect_back_or_default(default)
   2        session[:return_to] ? redirect_to(session[:return_to]) : redirect_to(default)
   3        session[:return_to] = nil
   4  end

posted by Png satoko on Fri 23 Nov 2007 at 15:06

http://railscasts.com/episodes/80
via Railscasts

Rails2.0が数週間でリリースの見通し。Railscastでは数回に渡ってRails2.0をピックアップするそうです。今回のポッドキャスト見どころは下記。

***

index.html.erb

  • particalには@todos:Arrayを渡せばpartial(_todo.html.erb)で表示してくれる
       1  <% title 'Todos' %>
       2  <%= render :partial => @todos %>
    

show.html.erb

  • particalには@todo:Todoを渡せばpartial(_todo.html.erb)で表示
       1  <% title h(@todo.title) %>
       2  <%= render :partial => @todo %>
       3  <%= h(@todo.description) %>
    

_todo.html.erb

  • div_forでid(ex. todo_1, todo_2..), classを生成してくれる
       1  <% div_for todo do %>
       2    <h2><%= link_to h(todo.title), todo %></h2>
       3  <% end %>
    

new.html.erb

  • form_for @todo(Todo)を渡す
       1  <% title 'New Todo' %>
       2  <% form_for @todo |f| do %>
       3  <%= f.text_field :title %>
       4  <%= f.text_area :description %>
       5  <% end %>
    
posted by Png satoko on Fri 23 Nov 2007 at 12:01
Contents
プラグイン:RESTful OpenID Authenticationの導入
Rails2.0 feature:viewについて
Comments
瀧内元気: MacOS版は以下にあります * [genki/ViMouse](https://githu... '23-1
KingofSmack: Here also good reads for this mobile applicatio... '14-5
Spencer: You don't have to re-compile it, this version w... '14-4
staiano: Any chance we can get a recompile for 10.9? '14-1
dsjf: https://gist.github.com/6bf1bf2c3cbb5eb6e7a7 これ... '13-1
Services from s21g
twpro(ツイプロ)
Twitterプロフィールを快適検索
地価2009
土地の値段を調べてみよう
MyRestaurant
自分だけのレストラン手帳
Formula
ブログに数式を埋め込める数式コミュニティ