Viridians on Rails


Published on

Ruby on Rails KT for any new joiner.

Published in: Technology
  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide
  • Ramesh - Vista
  • Start -> Run -> cmd > cd C:
    ubyonrails > use_ruby > cd C:
    ails_apps > rails project_name -d mysql <<project_name>>/ ..../app ......../controller -> A controller handles a web request from the user. ......../helpers -> Functions which help GUI mainly. ......../models -> Each file corresponds to a table in database. ......../views ............../layouts -> template of view files. ............../<controller_name> -> folder corresponding to each controller. ................../viewfiles.html.erb -> Run it through ruby interpreteur and generate html file. A view file corresponding to each function in a controller. ..../config ......../environments -> Holds 3 configuration files one each for production, test and development env. ......../initializers -> Constants. ......../environment file -> General configuration. ......../database.yml file -> Database connection configuration per environment (prod, test, dev). ......../routes file -> Routing of incoming web requests to appropriate code. ..../db ......../migrate -> Holds migration files to creata tables, upload data, upload test data, etc. (like SQL scripts) ......../seed ............../always -> yml files for reference data. ............../before_others -> Holds yml files needed to be run always first. ......../schema.rb -> Holds database table structures. Rails automatically creates it. Never manually change it. ......../seeds.rb -> ignore. ..../doc -> RubyDocs. Ignore not important ..../lib -> ignore ..../log -> ignore ..../public ......../images -> Holds pictures that are to be shown on website. ......../javascript -> Javascript. ......../stylesheets -> CSS. ..../private -> Does not come with rails but at Viridians we add this folder to store user images and files. The public folder is exposed and hence a security risk. ..../script -> Scripts to create, manage and launch various rails services. ..../test -> ignore ..../tmp -> ignore ..../vendor ......../plugins -> 3rd party Plugins used by the project. ......../gems -> Holds 3rd party gems which have been frozen. README-> ignore Rakefile-> ignore
  • Start MYSQL Server   > cd project_name > ruby script/server => Booting Mongrel => Rails 2.3.2 application starting on => Call with -d to detach => Ctrl-C to shutdown server   Go to browser and type http://localhost:3000/
  • > ruby scriptgenerate scaffold contact name:string weblink:string email:string password:string -> Creates contacts_controller with new, create, edit, update, delete, show, index methods. Contacts model and contacts view folder with new, edit, show, index view files. Links accessible are   > ruby scriptgenerate controller password -> Rails promotes creating restful design. Now considering, we need to create 3 functions, edit_password, forgot_password, create_random_password. Instead of adding them to contacts controller, create a dummy controller called passwords and dump these functions in the passwords controller.   > ruby scriptgenerate model page name:string header_str:string -> Creates a model file alone / table.   rake db:drop -> Drop database schema   rake db:create -> Add database schema   rake db:migrate RAILS_ENV=production VERSION=<<>> -> Create tables and upload datavalues based on db/migrations files   > ruby script/server => Booting Mongrel => Rails 2.3.2 application starting on => Call with -d to detach => Ctrl-C to shutdown server
  • rake db:drop -> Drop database schema rake db:create -> Add database schema  rake db:migrate RAILS_ENV=production VERSION=<<>> -> Create tables and upload datavalues based on db/migrations files   > ruby script/server => Booting Mongrel => Rails 2.3.2 application starting on => Call with -d to detach => Ctrl-C to shutdown server
  • Sessions in Rails Sessions configuration at …configinitializerssession_store.rb ActionController::Base.session = { :key => '_blabla', :secret => ‘….‘} ActionController::Base.session_store = :active_record_store Store session in DB at …dbmigratecreate_tables.rb  sessions table Some functions at …appcontrollersapplication_controller.rb current_user_session, current_user, require_user, require_no_user Methods in Models User Model Virtual attributes on object def name return first_name + last_name end Static Methods def self.randomize_username …. End Database queries User.find_by_first_name(‘Vikram’) User.all(:conditions => {:first_name => ‘Vikram’, :last_name => ‘Aditya’}, :order => “created_at DESC”) User.first(:conditions => {:first_name => ‘Vikram’})
  • Viridians on Rails

    1. 1. on Why Rails? How Rails? Please find latest version of the presentation at
    2. 2. Web World <ul><li>What is a website? </li></ul><ul><ul><li>Content available remotely over a browser. </li></ul></ul><ul><li>What is a web application? </li></ul><ul><li>Create Retrieve Update Delete (CRUD) operations on content designed for a purpose. </li></ul><ul><li>What is an enterprise application? </li></ul><ul><li>Applications / IT that augments business for an organization. </li></ul><ul><li>What is SAAS? </li></ul><ul><li>Packaging enterprise applications as web apps. </li></ul>
    3. 3. Software as a Service <ul><li>Why SAAS? </li></ul><ul><ul><li>Entry cost is low: Don’t care to maintain server and for that matter IT staff. </li></ul></ul><ul><ul><li>Don’t care OS. </li></ul></ul><ul><ul><li>Don’t care programming language and database application. </li></ul></ul><ul><ul><li>Don’t care how much hard disk space. </li></ul></ul><ul><ul><li>Don’t care where I work from. </li></ul></ul><ul><li>Why not SAAS? </li></ul><ul><ul><li>Data is business and your data on someone else's server - Can I trust? </li></ul></ul><ul><ul><li>Portability - Can I move out and still function safely?  Port out and port in data </li></ul></ul><ul><ul><li>Security! security! security!   </li></ul></ul><ul><ul><li>How much can I customize it?  Provide customization for client to play with. </li></ul></ul><ul><ul><li>Integration with other applications?  WEB API </li></ul></ul><ul><li>SAAS != Rocket Science </li></ul><ul><ul><li>But useful only if we can support complex business logic, and write complex code to counter the WHY NOT SAAS complications. </li></ul></ul>
    4. 4. Why Rails? <ul><li>Convention (Rails) versus Configuration (Java). </li></ul><ul><li>Model View Controller (MVC) architecture. </li></ul><ul><li>Don't Repeat yourself (Reuse). </li></ul><ul><li>Agile Methodology (Rails) versus SDLC (Java). </li></ul><ul><li>Based on Ruby -> OOL, Interpreted Lang, Simple, Intuitive, Reflective (pass code as string and make it run), Command line support, etc. </li></ul><ul><li>Hottest technologies supported: Ajax, Jquery, CSS, Oracle, MySQL, SQLLite, RESTful, APIs, XML, JSON, Web APIs, etc. </li></ul><ul><li>Database independent applications. </li></ul><ul><li>Open Source. Good support from a growing community. </li></ul><ul><li>No need for heavy IDEs. </li></ul><ul><li>Lots of behind the scene magic: Modes of operation: development, test, production, In built caching, testing, data migration support. </li></ul>
    5. 5. Why is Rails difficult to learn? <ul><li>Because it is a shift in paradigm </li></ul><ul><li>Individuals and interaction over processes and tools </li></ul><ul><li>Agile over SDLC </li></ul><ul><li>Working software over comprehensive documentation </li></ul><ul><li>Interpreted language over c ompile language </li></ul><ul><li>Customer collaboration over contract negotiation </li></ul><ul><li>Responding to change over following a plan </li></ul><ul><li>C onstraints ( Rails) over flexibility (Java ) </li></ul>
    6. 6. But the question still remains… <ul><li>“ Rails reduces our entry cost to SAAS”. </li></ul><ul><li>We want to build highly commoditized simple to use SAAS products which solve complex business problems at a low cost for social causes. </li></ul><ul><ul><li>Don’t want to repeat ourselves / reinvent wheel. </li></ul></ul><ul><ul><li>Believe in setting a convention to achieve efficiency. </li></ul></ul><ul><ul><li>Believe in BEST OF ALL WORLDS approach through open source APIs / projects. </li></ul></ul><ul><ul><li>We want to share, work together and grow together. </li></ul></ul><ul><ul><li>Want to reduce focus on technicalities and increase focus on complex business logic and getting products production ready. </li></ul></ul>Whose using Rails? … why is Viridians on Rails?
    7. 7. LEARNING TO LEARN RAILS YOURSELF Rails is based on conventions. To start, you need to know the basics. But from then on, learning rails is all about self-experimenting, Googling and discovering new conventions / plugins / gems / open source APIs which solve or simplify your problems.
    8. 8. Dev. environment <ul><li>Window XP / 32 bit machines: MySQL (32 bit), Ruby 1.8.7, Rails 2.3.4, Mongreal Server, Scite text editor </li></ul><ul><li>If you work on Vista, contact us. </li></ul><ul><li>Download (209 MB) our drag drop environment from </li></ul><ul><li>Unzip contents into folder: C: ubyonrails </li></ul><ul><li>Double Click and open Instant Rails </li></ul><ul><li>It will give error that apache not working. Its fine press OK and continue. </li></ul>
    9. 9. Rails project Note: Gem is the ruby equivalent of Java jar. Plugin is nothing but an unpacked jar file. Gem code cannot be changed but plugin code can be changed.
    10. 10. Is my env. working fine? *Note: is localhost by default in Windows
    11. 11. Getting started… Types of methods for Models: - Virtual Attributes - Static Methods
    12. 12. Rails Magic in MVC terms (Gem) (Gem) (Gem)
    13. 13. <ul><li>Rake (Ruby Make) is a build tool. Uses: </li></ul><ul><ul><li>Pulling a list of members to send out an email. </li></ul></ul><ul><ul><li>Doing nightly data calculations and reporting. </li></ul></ul><ul><ul><li>Expiring and regenerating caches. </li></ul></ul><ul><ul><li>Making backups of my database and subversion repository. </li></ul></ul><ul><ul><li>Running any sort of data manipulation script. </li></ul></ul><ul><ul><li>Create and delete databases, tables and reference data. </li></ul></ul><ul><ul><li>Learn more at </li></ul></ul><ul><li>Migrations in Viridians projects </li></ul><ul><ul><li>Add those yml files which need to be uploaded </li></ul></ul><ul><ul><li>before others in the before_others folder. </li></ul></ul><ul><ul><li>rake db:always is a rake task to load the data from </li></ul></ul><ul><ul><li>the yaml files located in db/seed/always. It deletes </li></ul></ul><ul><ul><li>the existing records in those corresponding tables </li></ul></ul><ul><ul><li>and recreates them. </li></ul></ul>Migrations & Rake Check your application at http://localhost:3000/contacts/
    14. 14. Other basics <ul><li>Sessions in Rails </li></ul><ul><ul><li>Sessions configuration at …configinitializerssession_store.rb </li></ul></ul><ul><ul><li>Store session in DB at …dbmigratecreate_tables.rb  sessions table </li></ul></ul><ul><ul><li>Some functions at …appcontrollersapplication_controller.rb </li></ul></ul><ul><li>Database queries </li></ul><ul><li>Validations </li></ul>
    15. 15. GIT Version Control <ul><li>Evolution of open source version controls: CVS  SVN  GIT </li></ul><ul><li>Features: </li></ul><ul><li>1. Distributed Repositories </li></ul><ul><li>2. Non Linear Development </li></ul><ul><li>3. Branching, Merging </li></ul><ul><li>4. Cryptic Authentication </li></ul><ul><li>Download: </li></ul><ul><li>Even most open source rails projects are on a social coding website called as </li></ul><ul><li>Viridians wants to use GIT to manage code as technologists spread across countries code on the same projects. </li></ul><ul><li>Presently we are developing capability to set up a GIT Server, and master and possibly simplify usage of GIT. Once, its done, we will issue a detailed KT and installation to all. </li></ul>
    16. 16. Your friends <ul><li>Your first rails project: </li></ul><ul><li>Online books: </li></ul><ul><li>One of the best way to learn a new language is to see real projects and the code in use. is the defacto social coding website used by most open source Rails projects, plugins, gems, etc. If you want to use a plugin and need a example of how to use it, Github even allows to search for code. </li></ul><ul><li>Screencasting has been core to the Rails community. Some well known video tutorials sites are: , , </li></ul><ul><li>Official Sources: (concepts), (API documentation), (easier to use api documentation) </li></ul><ul><li>Ask the group: </li></ul><ul><li>Test your CSS for all browsers </li></ul>
    17. 17. Ritvvij Parrikh [email_address] Thank You! Create a Viridians account at