rails

データベースの利用

dbの作成 $ rake db:createモデルの作成 userモデル プロパティは(name, username, location, about) $ rails g model user name:string username:string location:string about:text invoke active_record create db/migrate/20140626231858_create_users.r…

ルーターを触ってみる

URLルーティングは /config/routes.rb に定義されている get 'users/show/:username' => "users#show" と書いて、http://localhost:3000/users/show/hoge にアクセスすると、"users#show"の定義で usersコントローラのshowメソッドにフォワードされ、 params…

viewへの変数アサイン

コントローラ側で def show @user = Hash.new @user[:name] = 'letitride' endと書くとview側で <h1><%= @user[:name] %></h1>として参照する。勉強したこと hashを初期化するには@hash = Hash.new hashのkeyは:keyと書く viewの値参照はでくくる view側はそのままhas…

controllerの作成

controllerの作成 $ rails g controller {コントローラ名}コントローラ名は複数形が望ましいとのこと( exp members ) app/controllers/{コントローラ名}_controller.rb app/views/{コントローラ名}/ が作成される。

rbenv導入時のrailsコマンド

$ rails -v Rails is not currently installed on this system. To get the latest version, simply type: $ sudo gem install rails You can then rerun your "rails" command.とrailsはインストール済みだがrailsをインストールしろとのこと。調べてみると…