2008年5月24日 21:21

using will_paginate with rails 2.0

rails

指定依赖的gem(environment.rb):
 

Rails::Initializer.run do |config|

  # Require the latest version of haml
  config.gem "haml"

  # Require a specific version of chronic
  config.gem "chronic", :version => '0.2.3'

  # Require a gem from a non-standard repo
  config.gem "hpricot", :source => "http://code.whytheluckystiff.net"

  # Require a gem that needs to require a file different than the gem's name
  # I.e. if you normally load the gem with require 'aws/s3' instead of
  # require 'aws-s3' then you would need to specify the :lib option
  config.gem "aws-s3", :lib => "aws/s3"
end



然后解压到vender:
 

# Unpack all gems to vendor/gems
rake gems:unpack


 

Comments(0)

Tags:

2008年5月20日 19:58

get your grub back

linux

how to get your grub back when you reinstalled your windoz?

Comments(2)

Tags:

2007年12月23日 00:28

Using acts_as_taggable in Rails (quick reference)

未分类

 

Here are the quickfire steps to use the acts_as_taggable gem...

1. In your project database, add two tables, tags and tags_[model you're linking to], here's an example sql script:

CREATE TABLE `books` (
`id` int(6) UNSIGNED NOT NULL AUTO_INCREMENT,
`title` varchar(50) NOT NULL DEFAULT '',
`author` varchar(50) NOT NULL DEFAULT '',
`description` text NOT NULL,
`created_on` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`updated_on` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

CREATE TABLE `tags` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(30) NOT NULL DEFAULT '',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

CREATE TABLE `tags_books` (
`tag_id` int(11) NOT NULL DEFAULT '0',
`book_id` int(11) NOT NULL DEFAULT '0'
) ENGINE=InnoDB DEFAULT CHARSET=latin1;



2. at a command prompt, from in your project directory, run

gem install acts_as_taggable

3. Add this line right above the end in your environment.rb

require_gem 'acts_as_taggable'

4. Create a tag model. You can do this manually or with the generator like so:

ruby script\generate model Tag

5. In your target object's model.rb file (books.rb in this case) add

acts_as_taggable

6. In your target object's controller (books_controller.rb for us) add this line under your
if @books.save line..

@book.tag(params[:tags])

7. Add this to your _forms partial

tags for this book: <%= text_field_tag('tags', '') %>

8. To get the items to show in yor list.rhtml view, you can call them with this

<%= book.tag_names.join(" ") %>

That's the quick way to get acts_as_taggable working. For more functionality, check this out.

Comments(0)

Tags:

2007年12月19日 04:03

ddddd

未分类

Comments(0)

Tags:

2007年12月19日 03:54

rails code test

未分类

  1. def self.search(o,page)
  2.     conditions = ""
  3.     par = []
  4.    
  5.     if o.first_name
  6.       conditions << "firstName=? "
  7.       par << o.first_name
  8.     end
  9.    
  10.     if params[:category]
  11.       conditions << " AND " unless conditions.empty?
  12.       conditions << "category_id=?"
  13.       par << params[:category]
  14.     end
  15.  
  16.     conditions = nil
  17.     unless o.first_name?
  18.       conditions = ['s_first_name like ?', "%#{o.first_name}%"]
  19.     end
  20.     paginate :per_page => 5, :page => page,
  21.       :conditions => conditions, :order => 's_first_name'
  22.   end


 

Comments(0)

Tags:

Copyright © 2007

Webdesign, tvorba www stránek

Valid XHTML 1.1