「Ruby on Rails」の版間の差分

提供: sha.ngri.la
移動先: 案内検索
(deviseを使ってユーザ認証機能をつける)
(deviseを使ってユーザ認証機能をつける)
77行目: 77行目:
 
*[https://github.com/RailsApps/rails3-bootstrap-devise-cancan RailsApps/rails3-bootstrap-devise-cancan · GitHub]
 
*[https://github.com/RailsApps/rails3-bootstrap-devise-cancan RailsApps/rails3-bootstrap-devise-cancan · GitHub]
 
*[http://d.hatena.ne.jp/babie/20100729/1280381392 Railsの第4世代認証エンジンDeviseのREADMEを翻訳してみた - LazyLoadLife]
 
*[http://d.hatena.ne.jp/babie/20100729/1280381392 Railsの第4世代認証エンジンDeviseのREADMEを翻訳してみた - LazyLoadLife]
 +
*[http://d.hatena.ne.jp/hrendoh/20110906/1315282969 Rails3アプリにDeviseで簡単に認証システムを組み込む - hrendohの日記]

2012年9月8日 (土) 08:44時点における版

使えるようにするまでは、Mountain LionでRuby On Railsを使えるようにするまでのとおり。いまのところ、不具合なく動いています。

Rails アプリケーションを作る

  1. アプリケーションを作る
    $ rails new [アプリケーション名] -d mysql
    
  2. scaffoldを生成
    $ rails g scaffold [アプリケーション名] [カラム名1]:[メソッド名1] [カラム名2]:[メソッド名2] .....
    

    $ rails g scaffold interested id:integer url:string title:string tag:string lastmodified:datetime
    
  3. config/database.ymlを編集
  4. migrateを実行
    $ rake db:migrate
    
  5. config/routes.rbを編集。上記のrails g scaffoldの例なら、
    InterestedIn::Application.routes.draw do
      resources :interesteds
    end
    

    InterestedIn::Application.routes.draw do
      resources :interesteds
      root :to =>"interesteds#index"
    end
    

    と変更する。

リンクを作成する

link_to("表示する文字",url)

例えば、モデル名がinterestedでデータベースのカラム名がtitle、urlの場合(この認識で正しいのか?)、

link_to( interested.title ,interested.url) 

3番目の引数で<a>タグの属性も指定できる。

link_to( interested.title ,interested.url,{:target=>"_blank"})

Twitter Bootstrapを使う

  1. Gemfileに追加
    gem "twitter-bootstrap-rails", :group => :assets
  2. Terminal
  3. $ bundle install
    (略)
    $ rails g bootstrap:install
    (略)
    $ rails g bootstrap:layout [LAYOUT_NAME] [*fixed or fluid]
    

    例 fixedは1行、fluidは2行のことだと思う、、、

    $ rails g bootstrap:layout application fixed
    

Link

kaminariを使う

pagenationを使えるようになります。

表示を整える

deviseを使ってユーザ認証機能をつける