- column add -
DBA typically use to Utility. As follows..
==> alter table productor add column price decimal(8,3);
But Ruby use MIGRATE(Modification and Connection DB)
and modify code
Again Migrate
Validity add - location app/models/product.rb
You can see this page
Validates Method using
class Product < ActiveRecord::Base
validates_presence_of :title, :description, :image_url
validates_numericality_of :price
validates_uniqueness_of :title
validates_format_of :image_url,
:with => %r{\.(gif|jpg|png)$}i,
:message => "must be a URL for a GIF, JPG, or PNG image"
protected
def validate
errors.add(:price, "should be at least 0.01") if price.nil? || price < 0.01
end
end
Generate Dynamic scaffold
depot> ruvy script/generate scaffold product admin
Using following Source
http//media.pragprog.com/titles/rails2/code/depot_c/db/migrate/003_add_test_data.rb
http//media.pragprog.com/titles/rails2/code/depot_c/public/images
http//media.pragprog.com/titles/rails2/code/depot_c/public/stylesheets/depot.css
Enter: http://localhost:3000/admin/list You can see result
Create another Controller
depot> ruby script/generate controller store index
Request data from DB.
class StoreController < ApplicationController
def index
@products = Product.find_products_for_sale
end
end
=================product.rb======================>
def self.find_products_for_sale
find(:all, :order => "title")
end
=================add source======================>
Sunday, November 11, 2007
My Ruby Course..
Posted by woo choule ho at 11:49 PM
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment