README
Upload User: saiqg001
Upload Date: 2015-04-28
Package Size: 5057k
Code Size: 6k
Category:

Other systems

Development Platform:

Others

  1. == Welcome to Rails
  2. Rails is a web-application and persistence framework that includes everything
  3. needed to create database-backed web-applications according to the
  4. Model-View-Control pattern of separation. This pattern splits the view (also
  5. called the presentation) into "dumb" templates that are primarily responsible
  6. for inserting pre-built data in between HTML tags. The model contains the
  7. "smart" domain objects (such as Account, Product, Person, Post) that holds all
  8. the business logic and knows how to persist themselves to a database. The
  9. controller handles the incoming requests (such as Save New Account, Update
  10. Product, Show Post) by manipulating the model and directing data to the view.
  11. In Rails, the model is handled by what's called an object-relational mapping
  12. layer entitled Active Record. This layer allows you to present the data from
  13. database rows as objects and embellish these data objects with business logic
  14. methods. You can read more about Active Record in 
  15. link:files/vendor/rails/activerecord/README.html.
  16. The controller and view are handled by the Action Pack, which handles both
  17. layers by its two parts: Action View and Action Controller. These two layers
  18. are bundled in a single package due to their heavy interdependence. This is
  19. unlike the relationship between the Active Record and Action Pack that is much
  20. more separate. Each of these packages can be used independently outside of
  21. Rails.  You can read more about Action Pack in 
  22. link:files/vendor/rails/actionpack/README.html.
  23. == Getting started
  24. 1. Run the WEBrick servlet: <tt>ruby script/server</tt> (run with --help for options)
  25.    ...or if you have lighttpd installed: <tt>ruby script/lighttpd</tt> (it's faster)
  26. 2. Go to http://localhost:3000/ and get "Congratulations, you've put Ruby on Rails!"
  27. 3. Follow the guidelines on the "Congratulations, you've put Ruby on Rails!" screen
  28. == Example for Apache conf
  29.   <VirtualHost *:80>
  30.     ServerName rails
  31.     DocumentRoot /path/application/public/
  32.     ErrorLog /path/application/log/server.log
  33.   
  34.     <Directory /path/application/public/>
  35.       Options ExecCGI FollowSymLinks
  36.       AllowOverride all
  37.       Allow from all
  38.       Order allow,deny
  39.     </Directory>
  40.   </VirtualHost>
  41. NOTE: Be sure that CGIs can be executed in that directory as well. So ExecCGI
  42. should be on and ".cgi" should respond. All requests from 127.0.0.1 go
  43. through CGI, so no Apache restart is necessary for changes. All other requests
  44. go through FCGI (or mod_ruby), which requires a restart to show changes.
  45. == Debugging Rails
  46. Have "tail -f" commands running on both the server.log, production.log, and
  47. test.log files. Rails will automatically display debugging and runtime
  48. information to these files. Debugging info will also be shown in the browser
  49. on requests from 127.0.0.1.
  50. == Breakpoints
  51. Breakpoint support is available through the script/breakpointer client. This
  52. means that you can break out of execution at any point in the code, investigate
  53. and change the model, AND then resume execution! Example:
  54.   class WeblogController < ActionController::Base
  55.     def index
  56.       @posts = Post.find_all
  57.       breakpoint "Breaking out from the list"
  58.     end
  59.   end
  60.   
  61. So the controller will accept the action, run the first line, then present you
  62. with a IRB prompt in the breakpointer window. Here you can do things like:
  63. Executing breakpoint "Breaking out from the list" at .../webrick_server.rb:16 in 'breakpoint'
  64.   >> @posts.inspect
  65.   => "[#<Post:0x14a6be8 @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>, 
  66.        #<Post:0x14a6620 @attributes={"title"=>"Rails you know!", "body"=>"Only ten..", "id"=>"2"}>]"
  67.   >> @posts.first.title = "hello from a breakpoint"
  68.   => "hello from a breakpoint"
  69. ...and even better is that you can examine how your runtime objects actually work:
  70.   >> f = @posts.first 
  71.   => #<Post:0x13630c4 @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>
  72.   >> f.
  73.   Display all 152 possibilities? (y or n)
  74. Finally, when you're ready to resume execution, you press CTRL-D
  75. == Console
  76. You can interact with the domain model by starting the console through script/console. 
  77. Here you'll have all parts of the application configured, just like it is when the
  78. application is running. You can inspect domain models, change values, and save to the
  79. database. Starting the script without arguments will launch it in the development environment.
  80. Passing an argument will specify a different environment, like <tt>console production</tt>.
  81. == Description of contents
  82. app
  83.   Holds all the code that's specific to this particular application.
  84. app/controllers
  85.   Holds controllers that should be named like weblog_controller.rb for
  86.   automated URL mapping. All controllers should descend from
  87.   ActionController::Base.
  88. app/models
  89.   Holds models that should be named like post.rb.
  90.   Most models will descend from ActiveRecord::Base.
  91.   
  92. app/views
  93.   Holds the template files for the view that should be named like
  94.   weblog/index.rhtml for the WeblogController#index action. All views use eRuby
  95.   syntax. This directory can also be used to keep stylesheets, images, and so on
  96.   that can be symlinked to public.
  97.   
  98. app/helpers
  99.   Holds view helpers that should be named like weblog_helper.rb.
  100. config
  101.   Configuration files for the Rails environment, the routing map, the database, and other dependencies.
  102. components
  103.   Self-contained mini-applications that can bundle together controllers, models, and views.
  104. lib
  105.   Application specific libraries. Basically, any kind of custom code that doesn't
  106.   belong under controllers, models, or helpers. This directory is in the load path.
  107.     
  108. public
  109.   The directory available for the web server. Contains subdirectories for images, stylesheets,
  110.   and javascripts. Also contains the dispatchers and the default HTML files.
  111. script
  112.   Helper scripts for automation and generation.
  113. test
  114.   Unit and functional tests along with fixtures.
  115. vendor
  116.   External libraries that the application depends on. Also includes the plugins subdirectory.
  117.   This directory is in the load path.