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

Some important directories


App/Test->Most of our work takes placed in app/test directory.
DocàThe doc directory is used for application documentation. It is produced using RDoc. If you run rake doc:app, you’ll end up with HTML documentation in the directory doc/app.

LibàThe lib directory holds application code that doesn’t fit neatly into a model,view, or controller. For example, you may have written a library that creates PDF receipts that your store’s customers can download.
1 These receipts are sent directly from the controller to the browser (using the send_data method).
The code that creates these PDF receipts will sit naturally in the lib directory.
The lib directory is also a good place to put code that’s shared among models,views, or controllers.

Rake TasksàRails provides a Rake task to tell you the latest migration that has been performed.

LogàAs Rails runs, it produces a bunch of useful logging information. This is stored (by default) in the log directory. Here you’ll find three main log files, called development.log, test.log, and production.log. The logs contain more than just simple trace lines; they also contain timing statistics, cache information, and expansions of the database statements executed.

PublicàThe public directory is the external face of your application. The web server takes this directory as the base of the application. Much of the deployment configuration takes place here.
ScriptàThe script directory holds programs that are useful for developers. Run most of these scripts with no arguments to get usage information. About Displays the version numbers of Ruby and the Rails components being used by your application, along with other configuration information. Dbconsole Allows you to directly interact with your database via the command line.

Console->Allows you to use irb to interact with your Rails application methods. irb

Destroy->Removes auto generated files created by generate.

Generate->A code generator. Out of the box, it will create controllers, mailers, models, scaffolds, and web services. You can also download additional generator modules from the Rails website.2 Run generate with no arguments for usage information on a particular generator, for example: ruby scriptgenerate migration.

Plugin->Helps you install and administer plug-ins—pieces of functionality that extend the capabilities of Rails.

Runner->Executes a method in your application outside the context of the Web. You could use this to invoke cache expiry methods from a cron job or handle incoming e-mail.

Server->Runs your Rails application in a self-contained web server, using Mongrel (if it is available on your box) or WEBrick. We’ve been using this in our Depot application during development.

Benchmarker->Generates performance numbers on one or more methods in your application.

Profiler->Creates a runtime-profile summary of a chunk of code from your application.

Request->Creates a runtime-profile summary of a URI request processed by your application.

TempàIt probably isn’t a surprise that Rails keeps its temporary files tucked up in the tmp directory. You’ll find subdirectories for cache contents, sessions, and sockets in here.

VenderàIs this directory where third party code live.

Thursday, February 17, 2011

question answer


1.What is ruby on rails????
->Ruby on Rails is a framework that makes it easier to develop, deploy, and
maintain web applications.
2.What is framework?????????
->Framework is the collection of software tools which help to develop application in easy step, pre-written code libraries and data organization structure to assist in writing web application.
3.What is ruby on rails application architecture ???????
->Ruby on rails follow MCV architecture.
MODELS->The model is responsible for maintaining the state of the application. Model Sometimes this state is transient, lasting for just a couple of interactions with the user. Sometimes the state is permanent, and will be stored outside the application, often in a database. A model is more than just data; it enforces all the business rules that apply
to that data.
VIEWS->The view is responsible for generating a user interface, normally based view on data in the model.
CONTROLLERS->Controllers orchestrate the application. Controllers receive incoming events Controllers(normally user input), interact with the model, and display an appropriate
view to the user.
4.Why ruby on rails????????????
->It gives agility to web development.
->Developer can create web application width neat effect.
->Rapid development of application.
->Convention Over configuration : Less code, Less Repetition.
-> Not need of XML.
->ROR has support  of rest services which simple and fast.
->ROR has build command RAKE which make development fast and easy.
->Application is easy to maintain when application grow.
->ROR has build in testing.
5.What is active  record????????????
->Active record is the ORM(Object relational Mapping ) layer supply  width rails. It closely follow the ORM model: tables map to the classes, rows to the objects and colons to object attributes. 
6.What is active migration?????????
->Active record is an approach to accessing data in a database. A database object or view is wrapped into a class; thus an object instance is tied to a single row in the table. After creation of an object, a new row is added to the table upon save. Any object loaded gets its information from the database; when an object is updated, the corresponding row in the table is also updated. The wrapper class implements accessor methods or properties for each column in the table or view.

Migrations can manage the evolution of a schema used by several physical databases. It‘s a solution to the common problem of adding a field to make a new feature work in your local database, but being unsure of how to push that change to other developers and to the production server. 
         
7.Explain MCV working process in ROR?????
->IN Rails application, incoming requests are first sent to a router, which 
works out where in the application the request should be sent, and how
the request itself should be parsed. Ultimately, this phase identifies a
particular method (called an action in Rails parlance) somewhere in the action
controller code. The action might look at data in the request itself, it
might interact with the model, and it might cause other actions to be
invoked. Eventually the action prepares information for the view which
renders something to the user.

8.What is session and cookies???????
->Session: are used to store user information on the server side. 
cookies: are used to store information on the browser side or we can say client side 
Session : say session[:user] = “pravin_mishra” it remains when the browser is not closed.
9.What is script directory?????????
->The scripts directory holds programs that are useful for developers. Run
any of these scripts with no arguments to get usage information.

  • benchmarker
Get performance benchmarks on one or more methods in your application.
  • breakpointer
A client that lets you interact with running Rails applications.
  • console
Allows you to use irb to interact with your Rails application methods. irb
  • destroy
Removes autogenerated files created by generate.
  • generate
A code generator. Out of the box, it will create controllers, mailers,models, scaffolds, and web services
  • profiler
Creates a runtime-profile summary of a chunk of code from your
application.
  • runner
Executes a method in your application outside the context of the web.
You could use this to invoke cache expiry methods from a cron job,
or handle incoming e-mail.
  • server
A WEBrick-based server that will run your application. 
10.What is request.xhr????
-> A request.xhr tells the controller that the new Ajax request has come, It always return Boolean values (TRUE or FALSE).
11.What is use of  SUPER  in ROR????
->Ruby uses the super keyword to call the super class implementation of the current method.
12.What is ORM in rails????
->ORM tends for Object-Relationship-Model, it means that your Classes are mapped to table in the database, and Objects are directly mapped to the rows in the table.
13. What is the Install rail package????
->There are several packages that you can download and install. The prebuilt Rails installer called Install rail which currently is only for Windows.
14.How will you update rails????
C:\InstantRails-2.0-win_2\rails_apps>gem update rails
15.How to clean up previous library????
C:\InstantRails-2.0-win_2\rails_apps>gem cleanup
16.How to update previous worked file after updating rails????
C:\InstantRails-2.0-win_2\rails_apps>rake rails:update