Rails
(Rails3.2.12) config/routes.rb Redirect www Subdomain to Your Apex Domain Using the Rails Router | Big Nerd Ranch Blog constraints(host: /^(?!www\.)/i) do match '(*any)' => redirect { |params, request| URI.parse(request.url).tap { |uri| ur…
問題 link_to に『:protocol => 'https://'』しても、本番環境でhttpsにならない <%= link_to 'クリック', hoge_path, :protocol => 'https://' %> 解決 『:only_path => false』オプションが無いとprotocolが削除されるらしい Railsのlink_toメソッドでhttp…
(Rails3.2.12) 問題 一度httpsのページを表示すると、他のページ移ってもにhttpに戻らない。 解決策 例:hoges_controller の表示をhttpにリダイレクト app/view/controllers/application_controller.rb def redirect_to_http_from_https redirect_to :only_…
(Rails3.2.12) プロジェクト作成 rails new sortable_table -T cd new sortable_table rails g scaffold Product name price:decimal released:date rake db:migrate 確認用初期データ投入 db/seeds.rb Product.delete_all Product.create(name: "Katsuo", p…
コントローラのメソッドをビューから(ヘルパーも?)呼びたい時に使う for example #228 Sortable Table Columns - RailsCasts app/controllers/products_controller.rb class ProductsController < ApplicationController helper_method :sort_column, :so…
(Rails3.2.12)ファイル作成して下記のようにするapp/controllers/registrations_controller.rb class RegistrationsController < Devise::RegistrationsController protected def after_update_path_for(resource) hoge_path end end
問題 ブーリアン値 hoge が ture 以外を検索したい DBの状態 dbにカラム foobar で nil x5、false x1、true、x0。 true以外が計6コ。 User.where(:foobar => nil).count (0.3ms) SELECT COUNT(*) FROM `users` WHERE `users`.`foobar` IS NULL => 5 User.whe…
(Rails3.2.12) 原因 Passing the format in the template name is deprecated. Please pass render with :formats => [:html] instead. - donghai821の日記 render に拡張子つけてるのが原因らしい format.html { render :file => "#{Rails.root}/public/…
(Rails3.2.12) 症状 rails s してブラウザで表示しようとすると「Errno::EIO: Input/output error 〜 」とエラーが無限ループになる。 処置 原因不明。 PCを再起動したら直った。 New Rails App dies with Errno::EIO at / - Stack Overflow
rake db:migrate:reset したらエラーでた。 bundle exec rake db:migrate:reset rake aborted! Mysql2::Error: Table 'hoge_development.users' doesn't exist: SHOW FULL FIELDS FROM `users` rails_app_path/app/models/user.rb:73:in `<class:User>' :エラー出てる行</class:user>…
(Rails3.2.12) javan/whenever · GitHub 原因 /usr/bin/env ruby で sudo つけるとパス見つけられなくなる。 $ /usr/bin/env ruby -v ruby 1.9.3p385 $ sudo /usr/bin/env ruby -v /usr/bin/env: ruby: No such file or directory rubyインストールしてある…
(Rails3.2.11, ruby1.9.3) app/models/user.rb class User < ActiveRecord::Base : def confirm! super if confirmed? UserMailer.completion_of_registration(self).deliver end end app/mailers/user_mailer.rb class UserMailer < ActionMailer::Base def…
忘れるからメモ rake spec SPEC_OPTS="--format documentation"
(Rails3.2.11) http://railscasts.com/episodes/275-how-i-test?language=ja&view=asciicast 動作確認用プロジェクト作成 $ rails new test_email_in_rspec -T --skip-bundle $ cd test_email_in_rspec Gemfile group :test, :development do gem 'rspec-rai…
(Rails3.2.11) collectiveidea/delayed_job · GitHub Installation Gemfile gem 'delayed_job_active_record' shell bundle install rails generate delayed_job:active_record rake db:migrate 確認用メーラー作成 rails g user_mailer send_mail config/en…
(Rails3.2.11) javan/whenever · GitHub Installation Gemfile gem 'whenever', :require => false bundle install Getting started $ bundle exec wheneverize . [add] writing `./config/schedule.rb' [done] wheneverized! Example User rails g scaffold…
(ruby1.9.3, rails3.2.11) Case irb(main):001:0> y User.first.attributes User Load (0.3ms) SELECT `users`.* FROM `users` LIMIT 1 NoMethodError: undefined method `y' for main:Object Answer Rails console 'y' helper returns NameError rather tha…
rhtml-mode,rinari-mode を使用 (Emacs24.2) Case rhtml-mode で form-for を使うとインデントが効かなくなった <%= form_for @user, :html => { :class => "form-horizontal" } do |f| %> <%= f.name %> <% end %> Answer form_for でカッコ省略を省略しな…
validates :hoge, :uniqueness => true, :allow_nil => true
(Rails2.3.11) Case フォームで利用規約に同意のチェックボックスとかしたい Answer テーブルにカラム追加とかしない。 モデルとビューに書くだけ。 model validates :agreement, :acceptance =>true view <%= f.check_box :agreement %> 参考サイト フォト5…
(Rails2.3.11, twitter-bootstrap-rails2.2.0, MacOSX10.8) https://github.com/seyhunak/twitter-bootstrap-rails Bootstrap Case: 『Firefox のみ』bootstrapのアイコンが表示されない 師匠のブログで書かれてる問題なのだけど、アップデートして直ってる…
(MacOSX10.8, Rails3.2.8, Ruby1.9.3, Guard1.6.1, Emacs.app24.2) Case 新しいMacBook導入によりRails環境を入れ直したら guard コマンド 使えなくなった。 $ guard guard: command not found $ bundle exec guard #-> これは動くbundle exec 使えば動くけ…
スキャフォールド作成時にスタイルシートを作らない rails generate scaffold Hoge --no-stylesheets モデル作成時にマイグレーションファイルを作らない rails generate model Hoge --migration=false 参考サイト railsコマンド(rails) - Railsドキュメント
(Rails.3.2.8, Ruby1.9.3) irb(main):034:0> Time.now #=> 2012-12-23 13:55:02 +0900 irb(main):035:0> Time.current #=> Sun, 23 Dec 2012 04:55:06 UTC +00:00 irb(main):036:0> Time.current.localtime #=> 2012-12-23 13:55:11 +0900 irb(main):037:0> …
rake db:migrate のやり忘れ。
Sprockets::CircularDependencyError in Hoges#index : ~/hoge_project/app/assets/stylesheets/application.css has already been required :すでに application.css があるとか言ってる。/app/assets/stylesheets/ ディレクトリをのぞくと application_fly…
(Rails3.2.8, Rails1.9.3) seeds.rb spec/factories/ 以下のフィクスチャを利用する場合の例 require 'factory_girl' # require 'database_cleaner' Dir[Rails.root.join('spec/factories/*.rb')].each {|f| require f } hoge = FactoryGirl.create(:hoge) r…
(Rails3.2.8, Rails1.9.3) rails console production
(MacOSX10.8, Emacs24.2) 問題 Emacs の shell-mode からデプロイしようとしたPermission deniedとかいわれてできなかった。 $ cap deploy : Permission denied (publickey). : >|| **対策 >|| $ ssh-agent bash $ ssh-add ~/.ssh/id_rsaこれで cap deploy …
(Rails3.2.8, MySQL5.1) 問題 $ rake db:create rake aborted! Access denied for user 'hoge'@'localhost' to database 'hoge_development' 解決策 訂正20121227 権限あるユーザ作成 GRANT ALL ON *.* TO 'hoge'@'localhost' IDENTIFIED BY 'password' WITH…