If you want to unpack gem file - you can only unpack gems that you have installed, for example memcache-client:
gem unpack memcache-client
You may also use rake:
rake gems:unpack GEM=memcache-client
But some reason, the second does not work for my msysgit.
And, there is a discussion to use gem or plugin (http://www.robbyonrails.com/articles/2009/01/13/question-plugins-or-gems-or-both)
Thursday, February 25, 2010
rails commands for db dataset load and add
If you have db/dataset and db/dataset/dev folders that contain yml files, you can upload yml data to your db as follows:
rake db:dataset:load
However, if you load dev data with the following command, it nukes the db data from the previous command:
rake db:dataset:load DATASET=dev
Thus, you can run the following command to add dev data without nuking the existing data:
rake db:dataset:add DATASET=dev
Or if you have dev data first and wants to load db/dataset without nuking db/dataset/dev, you need to run the following:
rake db:dataset:add DATASET=.
rake db:dataset:load
However, if you load dev data with the following command, it nukes the db data from the previous command:
rake db:dataset:load DATASET=dev
Thus, you can run the following command to add dev data without nuking the existing data:
rake db:dataset:add DATASET=dev
Or if you have dev data first and wants to load db/dataset without nuking db/dataset/dev, you need to run the following:
rake db:dataset:add DATASET=.
Labels:
dataset,
db:dataset:add,
db:dataset:load,
rails,
yml
Monday, February 22, 2010
Rails plugins and gems
In each rails project, there is a folder named gems and plugins. They are lib files needed for the project. You can install a gem or a plugin into plugins folder. For example, if you want to install will-paginate, you can run the following in the command prompt windows. Then, your rails will recognize the gem:
$ gem install will_paginate
Successfully installed will_paginate-2.3.12
1 gem installed
Installing ri documentation for will_paginate-2.3.12...
Installing RDoc documentation for will_paginate-2.3.12...
However, when you share this lib of the project with others, others need to install the gem. But, if you put the lib into your project, others do not need to install the gem. Therefore, since rails 2.1, you can put the lib into the plugins folder with the follwing command:
$ ./script/plugin install git://github.com/mislav/will_paginate.git
Then, you can find the lib folder as follows: your_project/Vendor/plugins/will_paginate
$ gem install will_paginate
Successfully installed will_paginate-2.3.12
1 gem installed
Installing ri documentation for will_paginate-2.3.12...
Installing RDoc documentation for will_paginate-2.3.12...
However, when you share this lib of the project with others, others need to install the gem. But, if you put the lib into your project, others do not need to install the gem. Therefore, since rails 2.1, you can put the lib into the plugins folder with the follwing command:
$ ./script/plugin install git://github.com/mislav/will_paginate.git
Then, you can find the lib folder as follows: your_project/Vendor/plugins/will_paginate
Labels:
gem,
gem and plugin,
gem vs plugin,
install plugin,
plugin,
rails
Friday, February 19, 2010
rails polymorphic association
You can implement polymorphic associaton among tables COMMENTS, ARTICLES, PHOTOS as follows:
class Comment < ActiveRecord::Base
belongs_to :commentable, :polymorphic => true
end
class Article < ActiveRecord::Base
has_many :comments, :as => :commentable
end
class Photo < ActiveRecord::Base
has_many :comments, :as => :commentable
end
Then, you need the following statements in order to invoke article with comments:
# in model Article, collect article that has many comments
@article = Article.find(id)
@article_with_comments = @article.comments
Besides, you can also use the following statement to
@article = "articles".classify.constantize.find(id)
class Comment < ActiveRecord::Base
belongs_to :commentable, :polymorphic => true
end
class Article < ActiveRecord::Base
has_many :comments, :as => :commentable
end
class Photo < ActiveRecord::Base
has_many :comments, :as => :commentable
end
Then, you need the following statements in order to invoke article with comments:
# in model Article, collect article that has many comments
@article = Article.find(id)
@article_with_comments = @article.comments
Besides, you can also use the following statement to
@article = "articles".classify.constantize.find(id)
how to install plugin in rails project
You need to install plugins into your project. It is very simple once you know it. If you have the following error, it is because you don't have a plugin "acts_as_tree".
Error message:
undefined method `acts_as_tree' for #
In your model:
class Post < ActiveRecord::Base
acts_as_tree :order => "name"
end
In the command line windows/termial of your project directory, you can run the followin command:
./script/plugin install acts_as_tree
That is it. Now you don't see the error. And you should have "Vendor\plugins\acts_as_tree"
Error message:
undefined method `acts_as_tree' for #
In your model:
class Post < ActiveRecord::Base
acts_as_tree :order => "name"
end
In the command line windows/termial of your project directory, you can run the followin command:
./script/plugin install acts_as_tree
That is it. Now you don't see the error. And you should have "Vendor\plugins\acts_as_tree"
Thursday, February 11, 2010
ThinkingSphinx Basic command
1. Create a cofiguration file as config/development.sphinx.conf:
run rake ts:config
2. Indexin data:
run rake ts:in
or
run rake ts:index
3. Run ThinkingSphinx server daemon:
run rake ts:daemon:start
or not as a daemon
run rake ts:start
run rake ts:config
2. Indexin data:
run rake ts:in
or
run rake ts:index
3. Run ThinkingSphinx server daemon:
run rake ts:daemon:start
or not as a daemon
run rake ts:start
Labels:
config,
daemon,
rails,
search engine,
sphinx,
thinking sphinx
Saturday, February 6, 2010
session ActiveRecord in Rails
If your ActiveRecord session does not work but keeps generating session object in your sessions table, there is a possibility that you have changed the name of session "_session_session" to something else at Configuration/initializers/session_store.rb
Labels:
ActiveRecord,
memcached,
rails,
session,
sessions table
Subscribe to:
Posts (Atom)