ใช้ Rails.logger.info "Some debugging info I want to see in my development log."
แสดงบทความที่มีป้ายกำกับ rails3 แสดงบทความทั้งหมด
แสดงบทความที่มีป้ายกำกับ rails3 แสดงบทความทั้งหมด
วันอังคารที่ 3 เมษายน พ.ศ. 2555
rails 3: Rails logger outside controller and model
ทำอย่างไร ถ้าต้องการเขียน log นอก controller และ model ?
วันพุธที่ 28 มีนาคม พ.ศ. 2555
Rails3: How to config rails project no database ?
มีวิธีทำให้ Rails Project ไม่ต้องใช้ database อย่างไร
ใน config/application.rb ให้ comment #require 'rails/all'
ใน config/environments/development.rb ให้ comment #config.active_record.xxxxxxx...
และให้เพิ่ม code ข้างล่างนี้แทนที่
ใน config/application.rb ให้ comment #require 'rails/all'
ใน config/environments/development.rb ให้ comment #config.active_record.xxxxxxx...
และให้เพิ่ม code ข้างล่างนี้แทนที่
require "action_controller/railtie"
require "action_mailer/railtie"
require "active_resource/railtie"
require "rails/test_unit/railtie"
require "sprockets/railtie"
อ้างอิง : http://stackoverflow.com/questions/3954307/rails-3-how-do-i-avoid-database-altogetherวันอังคารที่ 27 มีนาคม พ.ศ. 2555
Rails : Formatting a date in a SQL query in Rails
ต้องการส่งวันที่และเวลา เข้าไปใน SQL Query ?
User.where("created_at < ?", Time.now.to_formatted_s(:db))
User.where("created_at < ?", Time.now.to_formatted_s(:db))
วันอาทิตย์ที่ 28 สิงหาคม พ.ศ. 2554
rails 3: Rails Footnotes
1. gem 'rails-footnotes', '>= 3.7', :group => :development
2. create footnotes.rb in initializers
3. insert code :
if defined?(Footnotes) && Rails.env.development?Footnotes.run! # first of all# ... other init codeFootnotes::Filter.prefix = 'mvim://open?url=file://%s&line=%d&column=%d'end
วันพฤหัสบดีที่ 18 สิงหาคม พ.ศ. 2554
rails 3: query_reviewer
วันอังคารที่ 28 มิถุนายน พ.ศ. 2554
Rails 3: load schema to production environment
- Development Environment : rake db:schema:dump
- Production Environment : rake db:schema:load RAILS_ENV=production
วันศุกร์ที่ 1 เมษายน พ.ศ. 2554
rails 3: foreign key in migration
class ExampleMigration < ActiveRecord::Migration def self.upcreate_table :products do |t|end
t.references :category
end
#add a foreign key
execute <<-SQL ALTER TABLE products ADD CONSTRAINT fk_products_categories FOREIGN KEY (category_id) REFERENCES categories(id) SQL add_column :users, :home_page_url, :string rename_column :users, :email, :email_address
def self.downrename_column :users, :email_address, :emailend
remove_column :users, :home_page_url
execute "ALTER TABLE products DROP FOREIGN KEY fk_products_categories"
drop_table :products
rails 3 : rake command on environment .
ใช้ parameter ที่ชื่อว่า RAILS_ENV ส่งค่าตาม environment ที่ต้องการตามตัวอย่างนี้
rake db:create RAILS_ENV=test
rake db:migrate RAILS_ENV=test
rake db:drop RAILS_ENV=test
rake db:create RAILS_ENV=test
rake db:migrate RAILS_ENV=test
rake db:drop RAILS_ENV=test
วันจันทร์ที่ 14 กุมภาพันธ์ พ.ศ. 2554
rails 3 : Configuration for PostgreSQL
- ติดตั้ง PostgreSQL ใน Rails 3 โดยไปเพิ่มสองบรรทัดใน Gemfile....
- source 'http://gemcutter.org'
- gem 'pg', '0.9.0'
- หลังจากนั้นใช้คำสั่ง > bundle install
- ใส่ config ใน database.yml ประมาณนี้
- ทดสอบ เข้า irb โดยใช้คำสั่ง > rails console
development:
adapter: postgresql
host: localhost
port: 5432
username: postgres
password: xxxxx
database: pg_development
schema_search_path: test
encoding: utf8
template: template0
สมัครสมาชิก:
บทความ (Atom)