0
Rails Plugins Navjeet Chabbewal Javaah Enterprises [email_address]
Agenda <ul><li>Brief Introduction to Rails Plugins </li></ul><ul><ul><li>Installation, removal, install directory </li></u...
So What are Rails Plugins <ul><li>Self contained libraries made specifically for Rails </li></ul><ul><li>Reuse code, yours...
Installation <ul><li>Installed per Rails app </li></ul><ul><li>First run  ./script/plugin discover  to add new plugin repo...
Installation Contd. <ul><li>Installs in vendor/plugins sub folder of Rails app root directory  </li></ul>
Remove Plugin <ul><li>Remove folder under vendor/plugins  </li></ul><ul><li>./script/plugin remove tabnav   </li></ul><ul>...
Tabnav <ul><li>Provides tabbed navigation </li></ul><ul><li>./script/plugin install svn://svn.seesaw.it/tabnav   </li></ul...
Tabnav Contd. <ul><li>app/models/main_tabnav.rb </li></ul><ul><ul><li>Modify this file to add tabs  </li></ul></ul><ul><ul...
Tabnav Contd. <ul><li>app/views/tabnav/_main_tabnav.rhtml   </li></ul><ul><ul><li>partial that generates tabs defined in  ...
Tabnav Contd. <ul><li>Tab screenshot - http://localhost:3001/dashboard  </li></ul>
Tabnav contd. <ul><li>The  titled  method gives your tabs a html ‘title’ attribute so you can have tooltips over your tab ...
acts_as_authenticated <ul><li>Simple authentication generator plugin      Quote from plugin website       &quot;The whole ...
AAA contd. <ul><li>./script/generate authenticated user account </li></ul><ul><ul><li>creates model user and it's migratio...
AAA Contd. <ul><li>Extend the basic plugin </li></ul><ul><ul><li>To set up email notifications refer to wiki (http://techn...
file_column <ul><li>Quote from plugin website &quot; This library makes handling of uploaded files in  Ruby on Rails  as e...
file_plugin contd. <ul><li>/script/plugin install  http://opensvn.csie.org/rails_file_column/ plugins/file_column/trunk </...
file_column contd. <ul><li>class CreateProducts < ActiveRecord::Migration   def self.up     create_table :products do |t| ...
file_column contd. <ul><li>Created a scaffold for <product> model </li></ul><ul><ul><li>Just make the &quot;image&quot; co...
file_column contd. <ul><li>display uploaded images  in your view (e.g. in view product page) </li></ul><ul><ul><li><%= ima...
acts_as_state_machine <ul><li>install from  http://elitists.textdriven.com/svn/plugins/acts_as_state_machine/trunk </li></...
AASM contd. <ul><li>Migration script example </li></ul><ul><ul><li>class CreateProjects < ActiveRecord::Migration   def se...
AASM contd. <ul><li>Update model <Project> </li></ul><ul><ul><li>class Project < ActiveRecord::Base     acts_as_state_mach...
Resources <ul><li>http://wiki.rubyonrails.org/rails/pages/Plugins - List of Rails Plugins </li></ul><ul><li>http://www.agi...
Upcoming SlideShare
Loading in...5
×

Useful Rails Plugins

7,100

Published on

This is a presentation I made at my local Northern Virginia Ruby Users Group. It discusses the install, setup and use of a few useful Ruby on Rails plugins.

Published in: Technology, Art & Photos
1 Comment
10 Likes
Statistics
Notes
  • Hay man you should have made it downloadable. Not making downloadable is against the open source concept... But any way great tutorial..........
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total Views
7,100
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
47
Comments
1
Likes
10
Embeds 0
No embeds

No notes for slide
  • Transcript of "Useful Rails Plugins"

    1. 1. Rails Plugins Navjeet Chabbewal Javaah Enterprises [email_address]
    2. 2. Agenda <ul><li>Brief Introduction to Rails Plugins </li></ul><ul><ul><li>Installation, removal, install directory </li></ul></ul><ul><li>Discuss usage of some useful plugins </li></ul><ul><ul><li>tabnav </li></ul></ul><ul><ul><li>acts_as_authenticated </li></ul></ul><ul><ul><li>file_column (file upload) </li></ul></ul><ul><ul><li>acts_as_state_machine </li></ul></ul>
    3. 3. So What are Rails Plugins <ul><li>Self contained libraries made specifically for Rails </li></ul><ul><li>Reuse code, yours or somebody else’s </li></ul>
    4. 4. Installation <ul><li>Installed per Rails app </li></ul><ul><li>First run ./script/plugin discover to add new plugin repositories    (on windows => ruby script/plugin discover) </li></ul><ul><li>./script/plugin install plugin_name </li></ul><ul><li>./script/plugin install svn://svn.seesaw.it/tabnav </li></ul><ul><li>./script/plugin install -x svn://svn.seesaw.it/tabnav </li></ul>
    5. 5. Installation Contd. <ul><li>Installs in vendor/plugins sub folder of Rails app root directory </li></ul>
    6. 6. Remove Plugin <ul><li>Remove folder under vendor/plugins </li></ul><ul><li>./script/plugin remove tabnav </li></ul><ul><li>Unlink with &quot; svn propdel svn:externals vendor/plugins &quot; </li></ul>
    7. 7. Tabnav <ul><li>Provides tabbed navigation </li></ul><ul><li>./script/plugin install svn://svn.seesaw.it/tabnav </li></ul><ul><li>./script/generate tabnav Main </li></ul><ul><ul><li>Generated two files </li></ul></ul><ul><ul><ul><li>app/models/main_tabnav.rb </li></ul></ul></ul><ul><ul><ul><li>app/views/tabnav/_main_tabnav.rhtml   </li></ul></ul></ul>
    8. 8. Tabnav Contd. <ul><li>app/models/main_tabnav.rb </li></ul><ul><ul><li>Modify this file to add tabs </li></ul></ul><ul><ul><ul><li>class MainTabnav < Tabnav::Base     add_tab do       named 'Dashboard'       links_to :controller => 'dashboard'     end </li></ul></ul></ul><ul><ul><ul><li>   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 </li></ul></ul></ul><ul><ul><ul><li>end </li></ul></ul></ul>
    9. 9. Tabnav Contd. <ul><li>app/views/tabnav/_main_tabnav.rhtml   </li></ul><ul><ul><li>partial that generates tabs defined in main_tabnav.rb </li></ul></ul><ul><ul><li>also has default stylesheet code </li></ul></ul><ul><li>Add this to layout/view </li></ul><ul><ul><li><%= start_tabnav :main %> </li></ul></ul><ul><ul><li><%= @content_for_layout %> </li></ul></ul><ul><ul><li><%= end_tabnav %> </li></ul></ul>
    10. 10. Tabnav Contd. <ul><li>Tab screenshot - http://localhost:3001/dashboard </li></ul>
    11. 11. Tabnav contd. <ul><li>The titled method gives your tabs a html ‘title’ attribute so you can have tooltips over your tab link. </li></ul><ul><li>The links_to method creates the tab’s link. You can use the same options as the usual ActionView’s url_for . </li></ul><ul><li>You can conditionally choose to show or not show a tab given a certain condition with the show_if method. </li></ul>
    12. 12. acts_as_authenticated <ul><li>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; </li></ul>
    13. 13. AAA contd. <ul><li>./script/generate authenticated user account </li></ul><ul><ul><li>creates model user and it's migration (which can be skipped) </li></ul></ul><ul><ul><li>creates account controller that has methods like login, signup, logout etc. </li></ul></ul><ul><li>include AuthenticatedSystem in application.rb </li></ul><ul><li>Add the line   before_filter :login_required in every controller you want protected. </li></ul>
    14. 14. AAA Contd. <ul><li>Extend the basic plugin </li></ul><ul><ul><li>To set up email notifications refer to wiki (http://technoweenie.stikipad.com/plugins/show/Mailer+Setup). </li></ul></ul><ul><ul><li>Can be used with authorization plugin by Bill Katz </li></ul></ul><ul><ul><ul><li>permit “railists or wanna_be_railist”, :except => :public </li></ul></ul></ul>
    15. 15. file_column <ul><li>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; </li></ul>
    16. 16. file_plugin contd. <ul><li>/script/plugin install http://opensvn.csie.org/rails_file_column/ plugins/file_column/trunk </li></ul><ul><li>rename trunk to file_column </li></ul><ul><li>create migration for <products> table </li></ul>
    17. 17. file_column contd. <ul><li>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 </li></ul>
    18. 18. file_column contd. <ul><li>Created a scaffold for <product> model </li></ul><ul><ul><li>Just make the &quot;image&quot; column ready for handling uploaded files </li></ul></ul><ul><ul><li>class Product < ActiveRecord::Base file_column :image end </li></ul></ul><ul><li>Update view (e.g. add product page) </li></ul><ul><ul><li><%= file_column_field &quot;product&quot;, &quot;image&quot; %> </li></ul></ul>
    19. 19. file_column contd. <ul><li>display uploaded images in your view (e.g. in view product page) </li></ul><ul><ul><li><%= image_tag url_for_file_column(&quot;product&quot;, &quot;image&quot;) %> </li></ul></ul>image from http://www.cafepress.com/rubyonrailsshop
    20. 20. acts_as_state_machine <ul><li>install from http://elitists.textdriven.com/svn/plugins/acts_as_state_machine/trunk </li></ul><ul><li>rename trunk to acts_as_state_machine </li></ul><ul><li>Create a model < Project> and table < projects> </li></ul>
    21. 21. AASM contd. <ul><li>Migration script example </li></ul><ul><ul><li>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 </li></ul></ul><ul><ul><li>end </li></ul></ul>
    22. 22. AASM contd. <ul><li>Update model <Project> </li></ul><ul><ul><li>class Project < ActiveRecord::Base    acts_as_state_machine :initial => :created  </li></ul></ul><ul><ul><li># 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 </li></ul></ul>
    23. 23. Resources <ul><li>http://wiki.rubyonrails.org/rails/pages/Plugins - List of Rails Plugins </li></ul><ul><li>http://www.agilewebdevelopment.com/plugins - List of Rails Plugins </li></ul><ul><li>http://nubyonrails.com/articles/2006/05/04/the-complete-guide-to-rails-plugins-part-i (Geoffry Grosenbach ) </li></ul><ul><li>http://blog.seesaw.it/articles/2006/07/23/the-easiest-way-to-add-tabbed-navigation-to-your-rails-app  </li></ul><ul><li>http://technoweenie.stikipad.com/plugins/show/Acts+as+Authenticated </li></ul><ul><li>http://www.kanthak.net/opensource/file_column/ </li></ul><ul><li>http://lunchroom.lunchboxsoftware.com/2006/1/21/acts-as-state-machine </li></ul><ul><li>http://elitists.textdriven.com/reminder-fsm.rb - Example for acts_as_state_machine </li></ul>
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×