Rails - how to use a plugin from github (how to install, utilize, etc)

妖精的绣舞 提交于 2019-12-10 11:05:59

问题


I'm trying to install a couple of different plugins for my rails 3 app. I cd to '/vendor/plugins/', then type git clone the_git_src_url.

I see the files in the /vendor/plugins/ directory. However when I try to use any of the tags provided by the plugin I get

uninitialized constant ContentsController::HTMLToTextileParser

PriceTag and html2textile are the two plugins I'm trying to use. This is what triggers the error above: <%= PriceTag.html_to_textile(@content.desc) %>

I'm working in development, I've tried to restart the server. Is there something I'm missing?


回答1:


html2textile is a Ruby gem, not a Rails plugin. To install a gem to be used in a Rails 3 app you can use builder adding the new gem in your Gemfile.

gem 'yourgem', :git=>'git://yourpath.git'

i.e.

gem 'html2textile', :git=>'git://github.com/thickpaddy/html2textile.git'

This will say that your application needs that gem to work; running bundle install will check if all the gems needed by your app are installed and will install the missing ones.


If you like manual labor and the gem of your interest is not available with the usual gem install yourgem, you can install it checking out the source code from the repository and building the gem by yourself.

To build html2textile:

$ git clone https://github.com/thickpaddy/html2textile.git
$ cd html2textile/
$ gem build html2textile.gemspec
$ gem install html2textile-1.0.0.jgp.gem
$ gem list | grep html2
html2textile (1.0.0.jgp)

Now you can require html2textile in you Rails app or in your plain Ruby scripts.

$ irb
> require 'rubygems'
=> true
> require 'html2textile'
=> true

pricetag can be handled in the same way.




回答2:


You should be using bundler with rails3. Add this to your Gemfile:

gem 'html2textile', :git=>'git://github.com/thickpaddy/html2textile.git'

then

bundle install




回答3:


lbz is right about html2textile.

Other plugins are installed as follows:

Rails2:

script/plugin install <source>

Rails3:

rails plugin install <source>

<source> would normally be sth. like git://github.com/xxx/yyy.git



来源:https://stackoverflow.com/questions/4833365/rails-how-to-use-a-plugin-from-github-how-to-install-utilize-etc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!