rails plugins l.
Download
Skip this Video
Download Presentation
Rails Plugins

Loading in 2 Seconds...

play fullscreen
1 / 23

Rails Plugins - PowerPoint PPT Presentation


  • 150 Views
  • Uploaded on

Rails Plugins. Navjeet Chabbewal Javaah Enterprises navjeet@javaah.com. 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.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Rails Plugins' - moral


Download Now An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
rails plugins

Rails Plugins

Navjeet Chabbewal

Javaah Enterprises

navjeet@javaah.com

agenda
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
so what are rails plugins
So What are Rails Plugins
  • Self contained libraries made specifically for Rails
  • Reuse code, yours or somebody else’s
installation
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
installation contd
Installation Contd.
  • Installs in vendor/plugins sub folder of Rails app root directory
remove plugin
Remove Plugin
  • Remove folder under vendor/plugins
  • ./script/plugin remove tabnav
  • Unlink with "svn propdel svn:externals vendor/plugins"
tabnav
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
tabnav contd
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 "params[:admin] == true" end

end

tabnav contd9
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 %>

tabnav contd10
Tabnav Contd.
  • Tab screenshot - http://localhost:3001/dashboard
tabnav contd11
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.
acts as authenticated
acts_as_authenticated
  • Simple authentication generator plugin     Quote from plugin website"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."
aaa contd
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 linebefore_filter :login_requiredin every controller you want protected.
aaa contd14
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
file column
file_column
  • Quote from plugin website" 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 RMagickto resize uploaded images and create thumb-nails. Files are stored in the filesystem and the filename in the database. "
file plugin contd
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
file column contd
file_column contd.
  • class CreateProducts < ActiveRecord::Migration  def self.up    create_table :products do |t|      t.column :name, :string      t.column :price, :floatt.column :image, :string    # stores uploaded file name    end  end  def self.down    drop_table :products  endend
file column contd18
file_column contd.
  • Created a scaffold for <product> model
    • Just make the "image" column ready for handling uploaded files

class Product < ActiveRecord::Base file_column :imageend

  • Update view (e.g. add product page)
    • <%= file_column_field "product", "image" %>
file column contd19
file_column contd.
  • display uploaded images in your view (e.g. in view product page)
    • <%= image_tag url_for_file_column("product", "image") %>

image from http://www.cafepress.com/rubyonrailsshop

acts as state machine
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>
aasm contd
AASM contd.
  • Migration script example

class CreateProjects < ActiveRecord::Migration  def self.up    create_table :projects do |t|      t.column :name, :stringt.column :state, :string    end  end  def self.down    drop_table :projects  end

end

aasm contd22
AASM contd.
  • Update model <Project>

class Project < ActiveRecord::Baseacts_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   endend

resources
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