LoginSignup
2
2

More than 5 years have passed since last update.

サンプルサイトの作成備忘録

Posted at

secret_baseエラーに対する対処

rails sで上記エラー発生→config/secrets.ymlを作成で解決 (http://guides.rubyonrails.org/upgrading_ruby_on_rails.html#config-secrets-yml)

bundle exec rubocop -a

robocop 単体ではコードの書き方判断のみだが、-a を付け加えることでコードの自動書き直しをしてくれる(バージョンの兼ね合いによる改善などに便利)

strong parameters

rails3.2での脆弱性改善→受け取るパラメータの種類をきちんと定義するためprivate関数へ定義

controllerを作成する意味

viewを作成する時のみ必要→なぜなのかについては、MVCアーキテクチャで確認(http://www.rubylife.jp/rails/ini/index7.html)

同じ画面内で複数のモデル操作?→ただURLを作るだけ

resources :articles do
resources :comments
end
→これだと、aritcle/:id/comment/:idというURLができてしまう

login実装(今回は利用しない)

参考サイト:http://amigobellick.blog.fc2.com/blog-entry-10.html
http://ztbuz.hateblo.jp/entry/2013/12/29/091025

passwordのハッシュ化

参考サイト:http://www.machu.jp/diary/20071023.html#p01

model-attr_??? 思い出し

特定のgemのみ実行

budle exec ***

テーブルにカラムの追加

http://www.rubylife.jp/rails/model/index7.html#section2
ex.password_digest:string をUserテーブルに追加
add_password_digest_to_users password_digest:string

N対Nの従属関係をhas_many と belongs_to

参考サイト:http://hagetak.hatenablog.com/entry/2014/11/17/113720

routeの必要タイミング

URLを作成するかどうか→処理するだけならいらない

アプリケーションの他の場所で、現在ログイン中のユーザを取得するための機能作成

class ApplicationController < ActionController::Base  
  protect_from_forgery  
  force_ssl  
  private  

  def current_user  
    @current_user ||= User.find(session[:user_id]) if session[:user_id]  
  end  

  helper_method :current_user  
end 

参考サイト:ja.asciicasts.com/episodes/270-authentication-in-rails-3-1

loginするためのフォームについて

リソースであるテーブルデータを編集するためではないので、form_forではなくform_tagを使用しています。フォームはsessions_pathに送信されるので、新たにSessionsControllerを作成します。\

参考サイト:ja.asciicasts.com/episodes/270-authentication-in-rails-3-1

中間テーブルとのリレーション(今回はtag,category)

collection_selectメソッドを利用
参考サイト:http://webos-goodies.jp/archives/50773406.html

基本的に処理はmodelから!

なるべく、modelに処理を任せて、controllerなどの影響度を狭める→拡張や変更でmodelを書けばいい状態に設定しておく

application_controller.rbで使うhelper_methodの意図

classで定義しているものにたいして、特定のメソッドをmoduleとして扱うため(moduleはhelperで定義されている)にhelper_methodを利用する。これは、moduleはオブジェクトの初期化などせず、ただ単に処理をするだけを期待するから

予約投稿機能の実装について

参考サイト:http://qiita.com/seiya1121/items/ae74be7c7a1e6a22ea46

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2