&tag(Rails3/基本);
*目次 [#sab11141]
#contents
*参考情報 [#vf359841]
-[[Rails]]

*基本 [#na7c54e0]
**プロジェクトの新規作成 [#n570b09d]
 rails new <PROJECT_NAME>


**scasffold [#w44d32ef]
 rails g scsaffold member name:
 rake db:migrate


**RESTfulなルーティングの定義route [#be751f5a]
-routes.rbに、以下のような定義があれば、
 resources :books
-RESTfulなルーティングが自動的に定義される。
,URL,アクションメソッド,リクエスト,ヘルパー,備考
,/books,index,GET,books_path books_url,一覧画面
,/books:id,show,GET,book_path(id) book_url(id),詳細画面
,/books/new,new,GET,new_book_path new_book_url,新規登録画面
,/books,create,POST,,新規登録処理
,/books/:id/edit,edit,GET,edit_book_path(id) edit_book_url(id),更新画面
,/books/:id,update,PUT,,更新処理
,/books/:id,destroy,DELETE,,削除処理



**一覧画面(index) [#zadb1f5e]
-books_controler.rbにindexを定義
#pre{{
  def index
    @books = Book.find(:all)
  end
}}
-index.html.erbで一覧表示する
#pre{{
<ul>
<% @books.each do |book|  %>
<li><%= book.title %>
<% end %>
</ul>
}}
*git [#o6752c8d]
**gitで管理する場合のお勧め.gitignore [#fb99c201]
-[[gitignore/Rails.gitignore at master &#183; github/gitignore &#183; GitHub:https://github.com/github/gitignore/blob/master/Rails.gitignore]]にあるのがよいっぽい。

**プロジェクトをgitで管理する [#m8087f18]
-プロジェクトのルートフォルダで以下を実行。
#pre{{
$ git init
$ git add .
$ git commit
}}


トップ   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS