Tag: Rails/Tips
config.autoload_paths += %W(#{config.root}/lib) config.autoload_paths += Dir["#{config.root}/lib/**/"]
Hoge -> 'hoge.rb' を読み込む Hoge::Mogu -> 'hoge/mogu.rb' を読み込む HogeMogu -> 'hoge_mogu.rb' を読み込む
rake assets:precompile
<%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %> <%= javascript_include_tag "application", "data-turbolinks-track" => true %>
<%= stylesheet_link_tag "application", media: "all" %> <%= javascript_include_tag "application" %>
//= require jquery //= require jquery_ujs //= require turbolinks <- 削除 //= require_tree .
include ActionView::Helpers::TextHelper
<%= Rails.version %>
<%= RUBY_VERSION %>
# You can have the root of your site routed with "root" root 'welcome#index'
class WelcomeController < ApplicationController def index end end
class User < ActiveRecord::Base def to_param username end end
module MySite class Application VERSION = "0.0.4" end end
module MySite class Application < Rails::Application VERSION = "1.1.0" end end
config.my_special_value = 'val'
Rails.application.config.my_special_value
Alias /wiki /home/sora/www/wiki <Directory /home/sora/www/wiki> PassengerEnabled Off AllowOverride All </Directory>
※設定が煩雑になるのでステージング環境(staging.rb)は追加しないほうが良いかも。
$ bundle install $ bundle exec rake db:migrate RAILS_ENV=staging $ bundle exec rails s -e staging
そのかわりに環境変数を使用する。
if ENV[API_MOCKING_FLG] == 1 # APIのモック処理 else # 通常のAPI処理 end
production: adapter: mysql2 encoding: utf8 pool: 5 socket: /tmp/mysql.sock database: <%= ENV['DATABASE_SCHEMA_NAME'] %> host: <%= ENV['DATABASE_HOST'] %> username: <%= ENV['DATABASE_USER_NAME'] %> password: <%= ENV['DATABASE_PASSWORD'] %>
db:seedを使ってデータを投入できる。
Book.create(title: "title1", author: 'author1', summary: 'summary1') Book.create(title: "title2", author: 'author2', summary: 'summary2')
bundle exec rake db:seed RAILS_ENV=development
bundle exec rake db:reset RAILS_ENV=development
bundle exec rake db:reset RAILS_ENV=development