Useful Rails Plugins

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

2 comments

Comments 1 - 2 of 2 previous next Post a comment

  • + guestade237 guestade237 2 years ago
    It was a good presentation, no new info tho. I was looking for some good doc examples for widget/tabnav.

    http://uvtimes.blog.com
  • + mrbless mrbless 2 years ago
    Hay man you should have made it downloadable. Not making downloadable is against the open source concept... But any way great tutorial..........
Post a comment
Embed Video
Edit your comment Cancel

8 Favorites

Useful Rails Plugins - Presentation Transcript

  1. Rails Plugins Navjeet Chabbewal Javaah Enterprises [email_address]
  2. Agenda
    • Brief Introduction to Rails Plugins
      • Installation, removal, install directory
    • Discuss usage of some useful plugins
      • tabnav
      • acts_as_authenticated
      • file_column (file upload)
      • acts_as_state_machine
  3. So What are Rails Plugins
    • Self contained libraries made specifically for Rails
    • Reuse code, yours or somebody else’s
  4. Installation
    • Installed per Rails app
    • First run ./script/plugin discover to add new plugin repositories    (on windows => ruby script/plugin discover)
    • ./script/plugin install plugin_name
    • ./script/plugin install svn://svn.seesaw.it/tabnav
    • ./script/plugin install -x svn://svn.seesaw.it/tabnav
  5. Installation Contd.
    • Installs in vendor/plugins sub folder of Rails app root directory
  6. Remove Plugin
    • Remove folder under vendor/plugins
    • ./script/plugin remove tabnav
    • Unlink with " svn propdel svn:externals vendor/plugins "
  7. Tabnav
    • Provides tabbed navigation
    • ./script/plugin install svn://svn.seesaw.it/tabnav
    • ./script/generate tabnav Main
      • Generated two files
        • app/models/main_tabnav.rb
        • app/views/tabnav/_main_tabnav.rhtml  
  8. Tabnav Contd.
    • app/models/main_tabnav.rb
      • Modify this file to add tabs
        • class MainTabnav < Tabnav::Base     add_tab do       named 'Dashboard'       links_to :controller => 'dashboard'     end
        •    add_tab do       named 'My Projects' # name assigned in the tab       titled 'Summary of project status'       links_to :controller => 'project', :action => 'list'     end add_tab do named 'Admin' links_to :controller => 'admin' show_if &quot;params[:admin] == true&quot; end
        • end
  9. Tabnav Contd.
    • app/views/tabnav/_main_tabnav.rhtml  
      • partial that generates tabs defined in main_tabnav.rb
      • also has default stylesheet code
    • Add this to layout/view
      • <%= start_tabnav :main %>
      • <%= @content_for_layout %>
      • <%= end_tabnav %>
  10. Tabnav Contd.
    • Tab screenshot - http://localhost:3001/dashboard
  11. Tabnav contd.
    • The titled method gives your tabs a html ‘title’ attribute so you can have tooltips over your tab link.
    • The links_to method creates the tab’s link. You can use the same options as the usual ActionView’s url_for .
    • You can conditionally choose to show or not show a tab given a certain condition with the show_if method.
  12. acts_as_authenticated
    • Simple authentication generator plugin      Quote from plugin website      &quot;The whole idea behind the plugin is that you generate the code once and add in your application specific authentication actions. This makes no attempt to decide how your application's authorizing works.&quot;
  13. AAA contd.
    • ./script/generate authenticated user account
      • creates model user and it's migration (which can be skipped)
      • creates account controller that has methods like login, signup, logout etc.
    • include AuthenticatedSystem in application.rb
    • Add the line   before_filter :login_required in every controller you want protected.
  14. AAA Contd.
    • Extend the basic plugin
      • To set up email notifications refer to wiki (http://technoweenie.stikipad.com/plugins/show/Mailer+Setup).
      • Can be used with authorization plugin by Bill Katz
        • permit “railists or wanna_be_railist”, :except => :public
  15. file_column
    • Quote from plugin website &quot; This library makes handling of uploaded files in Ruby on Rails as easy as it should be. It helps you to not repeat yourself and write the same file handling code all over the place while providing you with nice features like keeping uploads during form redisplays , nice looking URLs for your uploaded files and easy integration with RMagick to resize uploaded images and create thumb-nails. Files are stored in the filesystem and the filename in the database. &quot;
  16. file_plugin contd.
    • /script/plugin install http://opensvn.csie.org/rails_file_column/ plugins/file_column/trunk
    • rename trunk to file_column
    • create migration for <products> table
  17. file_column contd.
    • class CreateProducts < ActiveRecord::Migration   def self.up     create_table :products do |t|       t.column :name, :string       t.column :price, :float       t.column :image, :string     # stores uploaded file name     end   end   def self.down     drop_table :products   end end
  18. file_column contd.
    • Created a scaffold for <product> model
      • Just make the &quot;image&quot; column ready for handling uploaded files
      • class Product < ActiveRecord::Base file_column :image end
    • Update view (e.g. add product page)
      • <%= file_column_field &quot;product&quot;, &quot;image&quot; %>
  19. file_column contd.
    • display uploaded images in your view (e.g. in view product page)
      • <%= image_tag url_for_file_column(&quot;product&quot;, &quot;image&quot;) %>
    image from http://www.cafepress.com/rubyonrailsshop
  20. acts_as_state_machine
    • install from http://elitists.textdriven.com/svn/plugins/acts_as_state_machine/trunk
    • rename trunk to acts_as_state_machine
    • Create a model < Project> and table < projects>
  21. AASM contd.
    • Migration script example
      • class CreateProjects < ActiveRecord::Migration   def self.up     create_table :projects do |t|       t.column :name, :string       t.column :state, :string     end   end   def self.down     drop_table :projects   end
      • end
  22. AASM contd.
    • Update model <Project>
      • class Project < ActiveRecord::Base    acts_as_state_machine :initial => :created 
      • # can specify :column => 'column_name' default column name is state    # specify different states    state :created    state :estimating    state :bid    state :won, :enter => Proc.new {|project| Mailer.spread_the_good_news(project)}    state :executing          # specify events that change states    event :estimate do      transitions :to => :estimating, :from => :created    end    event :submit_bid do      transitions :to => :bid, :from => :estimating    end       end
  23. Resources
    • http://wiki.rubyonrails.org/rails/pages/Plugins - List of Rails Plugins
    • http://www.agilewebdevelopment.com/plugins - List of Rails Plugins
    • http://nubyonrails.com/articles/2006/05/04/the-complete-guide-to-rails-plugins-part-i (Geoffry Grosenbach )
    • http://blog.seesaw.it/articles/2006/07/23/the-easiest-way-to-add-tabbed-navigation-to-your-rails-app 
    • http://technoweenie.stikipad.com/plugins/show/Acts+as+Authenticated
    • http://www.kanthak.net/opensource/file_column/
    • http://lunchroom.lunchboxsoftware.com/2006/1/21/acts-as-state-machine
    • http://elitists.textdriven.com/reminder-fsm.rb - Example for acts_as_state_machine

+ navjeetnavjeet, 3 years ago

custom

8184 views, 8 favs, 1 embeds more stats

This is a presentation I made at my local Northern more

More info about this document

© All Rights Reserved

Go to text version

  • Total Views 8184
    • 8182 on SlideShare
    • 2 from embeds
  • Comments 2
  • Favorites 8
  • Downloads 21
Most viewed embeds
  • 2 views on http://www.lonerunners.net

more

All embeds
  • 2 views on http://www.lonerunners.net

less

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

Cancel
File a copyright complaint
Having problems? Go to our helpdesk?

Categories