Sunday, March 6, 2011

command in RAILS


1.Create application
C:\InstantRails-2.0-win_2\rails_apps\pravin>rails diligence
2.create database by command  and configure in config/databse.yml  or directly do both by command line database creation and configuration simultaneously.
C:\InstantRails-2.0-win_2\rails_apps\pravin>mysqladmin -u root create diligence_development
3.Database configuration
C:\InstantRails-2.0-win_2\rails_apps\pravin>development:
          Adapter: mysql
          Databse: diligence_development
          Username: root
          Password:
          Host: localhost
4.Description:
AdapterC:\InstantRails-2.0-win_2\rails_apps\pravin>Adapter tell rails what kind of database using.
DatabaseC:\InstantRails-2.0-win_2\rails_apps\pravin>gives the name of database.
Username and passwordC:\InstantRails-2.0-win_2\rails_apps\pravin>let our application to log in database.
HostC:\InstantRails-2.0-win_2\rails_apps\pravin>tells rails the computer name where application is running.
5. OR
C:\InstantRails-2.0-win_2\rails_apps\pravin>cd diligence
C:\InstantRails-2.0-win_2\rails_apps\pravin>rails –database=mysql diligence
6.Test your database configuration
C:\InstantRails-2.0-win_2\rails_apps\pravin>rake db:create RAILS_ENV=’development’
C:\InstantRails-2.0-win_2\rails_apps\pravin>rake db:migrate
7.Database Migration
C:\InstantRails-2.0-win_2\rails_apps\pravin>database migration represent a change we  want to make in database, expressed in a source file in database independent terms. This changes can update both in database SCHEMA and database TABLES.
8.Create product tables via scaffold
C:\InstantRails-2.0-win_2\rails_apps\pravin>ruby script/generate scaffold product title:string description:text image_url:string
9.Again we have need to do is to get rails to apply this migration to our development database.
C:\InstantRails-2.0-win_2\rails_apps\pravin>rake db:migrate
OK, all the groundwork has been done. We set up our diligence  application as a Rails project. We created the development database and configured our application to be able to connect to it. We created a product controller and a product model and used a migration to create the corresponding products table. And a number of views have been created for us. It’s time to see all this in action.

10.ROLL BACK YOUR APPLICATION
C:\InstantRails-2.0-win_2\rails_apps\pravin>rake db:migrate VERSION=0
(our schema will roll bake in previous time)

11.Now start webrick web based server

C:\InstantRails-2.0-win_2\rails_apps\pravin>ruby script/server

12.Adding missing colons

C:\InstantRails-2.0-win_2\rails_apps\pravin>ruby script/generate migration add_price_to_product price:decimal

13.Validating Input Field in Index Page.

Open app/models/product.rb

validates__presence_of :title, :description, :image_url
validates_mumericallity_of :price
validates_uniquness_off :title
validate :price_must_be_at_least_a_cent
validates_formate_of :image_url,
                                   :width=>%r{\.(jpg/png/gif)$}i,
                                   :message=>’must be url in PNG/JPG/GIF formate’

protecded:
def price_must_be_at_least_a_cent
         
          errors.add(:price ‘should at least .01 or greater’) if price.nil? || price<.01

end

14.Convert rupees into CURRENCY($ {DOLLER})
 
è<span class="price" ><%= number_to_currency(product.price) %></span>

15.Create controller along width view

C:\InstantRails-2.0-win_2\rails_apps\pravin>ruby script/generate controller store index

16. Link tag in rails

è<%= link_to “Hit me”, :action=>’edit’, :method=>:post %>

17.Button in rails

è<%= button_to “submit” %>

18.Image tag in rails

è<%= image_tag(product.image_url) %>

19. Add stylesheet in layout Page

è<%= stylesheet_link_tag “pravin”, :media=>”all” %>

20.Remove HTML tag

è<%=h truncate(product.description.gsub(/<.*?>/,''),
:length => 80) %>

21.Display Time

è<%= Time.now %>

22.Create Migration Containing our session

C:\InstantRails-2.0-win_2\rails_apps\pravin>rake db:session:create

23. Create new cart if not present

èsession[:cart] ||=Cart.new

24.NOTE: ruby generator only use for create database-backed models

25.How to get id, requested by button

èproduct=Product.find(parms[:id])
èparams object is use to hold the parameter pass by browser.

26. Delete old session

C:\InstantRails-2.0-win_2\rails_apps\pravin>rake db:sessions:clear

27. Command for list all rails task
C:\InstantRails-2.0-win_2\rails_apps\pravin>rails –tasks

28.To lock your application on current version.

C:\InstantRails-2.0-win_2\rails_apps\pravin>rake rails:freeze:gems
29. To lock your application on current version.

C:\InstantRails-2.0-win_2\rails_apps\pravin>rake rails:unfreeze

30.Freeze to recent version

C:\InstantRails-2.0-win_2\rails_apps\pravin>rake rails:freeze:edge

No comments:

Post a Comment