Feeds:
Posts
Comments

Archive for the ‘Plugin’ Category

Install
script/plugin install http://svn.techno-weenie.net/projects/plugins/attachment_fu/
Create table
class CreateUploadImages < ActiveRecord::Migration
def self.up
create_table :upload_images do |t|
t.column :parent_id,  :integer
t.column :content_type, :string
t.column :filename, :string
t.column :thumbnail, :string
t.column :size, :integer
t.column :width, :integer
t.column :height, :integer
t.column :product_id, :integer
end
end
def self.down
drop_table :upload_images
end
end
Model
class UploadImage < ActiveRecord::Base
belongs_to :product
has_attachment :content_type => :image,
:storage => :file_system,
:max_size => 500.kilobytes,
:resize_to => ‘320×200>’,
:thumbnails => { :thumb => ‘100×100>’ }
validates_as_attachment
end
Controller
class UploadImageController < ApplicationController
def new
@uplaod_image = UploadImage.new
end
def create
@upload_image [...]

Read Full Post »

Acts as Ferret

Install
script/plugin install svn://projects.jkraemer.net/acts_as_ferret/tags/stable/acts_as_ferret
In Model add this
class User < ActiveRecord::Base
acts_as_ferret( :fields => ['name', 'address', 'city'])
end
In Controller u add this
User.find_by_ferret(query)  # Query is a string representing your query
User.find_id_by_contents(query)
User.find_by_contents(query, {}, :conditions => {}, :order => ’ssss’, :limit => :all)
## Grab the search results for both models
@users = User.find_by_contents(query+”*”, :limit => :all)
@profiles = Profile.find_by_contents(query+”*”, :limit => :all)
## Combine the [...]

Read Full Post »

Pagination

Install
script/plugin install http://svn.cardboardrocket.com/paginating_find
Add extra parameters to find function
@students = Student.find(:all, :page => {:size => 10,:current => params[:page]})
Extra parameters
:size     Number of records per page (default 10).
:current     The current page. Defaults to the first page: 1.
:first     The first page. Defaults to the first page: 1.
:auto     Automatically load the next page during invocation of [...]

Read Full Post »

Rating in rails

Install
script/plugin install svn://rubyforge.org/var/svn/acts-as-rated/trunk/acts_as_rated
class Book < ActiveRecord::Base
acts_as_rated
end
u = User.find_by_name “guy”
b = Book.find “Catch 22″
b.rate 5, u
u = User.find_by_name “john”
b.rate 3, u
b.rating_average # => 4
Book.find_by_rating 2..3 # => [<Book:"Catch 22">]
b.find_rated_by User.find_by_name(“guy”) # => [<Book:"Catch 22">]

Read Full Post »

To set up Acts_as_authenticated, you need to:
1. Install the plugin: script/plugin install http://svn.techno-weenie.net/projects/plugins/acts_as_authenticated
2. Generate the user and account models: script/generate authenticated user account
3. Rake the DB to add the users table: rake db:migrate
4. Finally, add this line to application.rb controller so you can use the gem: include AuthenticatedSystem
That’s it! To create a new account, hit [...]

Read Full Post »