Tag: ruby on rails plugins

在Rails has_many中保存关联记录的顺序:通过关联

我正在开发一个Rails插件,其中包含一种修改has_many:关联中相关记录顺序的方法。 假设我们有以下型号: class Playlist :destroy has_many :songs, :through => :playlists_songs end class Song :destroy has_many :playlists, :through => :playlists_songs end class PlaylistsSong < ActiveRecord::Base belongs_to :playlist belongs_to :song end 如果我们改变播放列表歌曲的顺序(例如@playlist.songs.rotate! ),Rails不会触及playlists_songs表中的记录(我正在使用Rails 3.1),这是有道理的。 我想调用播放列表的歌曲=方法保存歌曲的顺序,但是,可以通过删除播放列表中的相关现有行并以正确的顺序创建新的行(以便:order => “id”可以在检索它们时使用)或者通过向playlists_songs添加sort:integer列并相应地更新这些值。 我没有看到任何允许这样做的回调(例如before_add)。 在ActiveRecord :: Associations :: CollectionAssociation中 ,相关的方法似乎是writer , replace和replace_records ,但我对最好的下一步将会失败。 有没有办法扩展或安全地覆盖这些方法之一,以允许我正在寻找的function(最好只针对特定的关联),或者是否有一个不同的,更好的方法呢?

rails插件没有安装

我正在尝试安装restful_authentication插件使用以下git … git://github.com/Satish/restful-authentication.git 我正在尝试使用以下命令安装… c:\ Users \ Admin \ Downloads \ _ rails_apps \ students> ruby script/plugin install git://github.com/Satish/restful-authentication.git 但它没有按预期安装,请帮助,谢谢。

从Rails插件向Rails引擎模型添加方法

我正在编写一个Rails插件来扩展Rails引擎。 即MyPlugin将MyEngine作为依赖项。 在我的Rails引擎上,我有一个MyEngine::Foo模型。 我想为这个模型添加新方法,所以我在我的插件app/models/my_engine/foo.rb创建了一个文件,其中包含以下代码: module MyEngine class Foo def sayhi puts “hi” end end end 如果我在插件虚拟应用程序上进入Rails控制台,我可以找到MyEngine::Foo ,但运行MyEngine::Foo.new.sayhi返回 NoMethodError:未定义的方法`sayhi’ 为什么MyPlugin无法看到MyEngine::Foo模型的更新? 我哪里错了?

Rails插件可以打包为WAR / JAR文件吗?

可以将插件打包为JAR / WAR文件,类似于整个Rails应用程序可以打包以在JRuby上部署的方式吗?

未定义的方法`model_name’

我正在为专辑控制器获取这种未定义的方法并为任何解决方案建模?… 用于ActiveRecord的未定义方法`model_name’:: Relation:Class 提取的来源(第6行): 3:>> 4:新专辑 5: 6:= form_for @albums do | f | 7:= f.error_messages 8:%p 9:= f.label:名字 =link_to ‘albums’, albums_path >> new album = form_for @album do |f| = f.error_messages %p = f.label :name = f.text_field :name %p = f.label :description = f.text_field :description, :rows => 3 %p = f.submit %p= link_to “Back […]

在Ruby on Rails中,将某些内容安装为gem还是作为插件有什么区别?

在http://github.com/collectiveidea/delayed_job上 它说: 要安装为gem,请将以下内容添加到config / environment.rb: config.gem ‘delayed_job’ 运行rake gems:install 与 要作为插件安装: script/plugin install git://github.com/collectiveidea/delayed_job.git 将它安装为gem还是作为插件有什么区别? 另外,第一种方法只是安装gem 2.0.3,这可能是tobi的版本? ( rake gems:install通过gem list -r delayed_job安装版本)是http://github.com/tobi/delayed_job吗? “插件”方法明确表示它是集体版本? 你安装哪一个不重要吗?

RoR2.8和Heroku:我安装了一个插件,在本地工作,现在heroku根本不起作用

heroku日志提出: ==> dyno-3334279.log (crash) <== /app/fd916ea6-bad5-440e-a560-405ef5e3beee/home/.bundle/gems/ruby/1.8/gems/searchlogic-2.4.19/lib/searchlogic/named_scopes/conditions.rb:81:in `method_missing': undefined method `has_attached_file' for # (NoMethodError) from /app/fd916ea6-bad5-440e-a560-405ef5e3beee/home/.bundle/gems/ruby/1.8/gems/searchlogic-2.4.19/lib/searchlogic/named_scopes/association_conditions.rb:19:in `method_missing’ from /app/fd916ea6-bad5-440e-a560-405ef5e3beee/home/.bundle/gems/ruby/1.8/gems/searchlogic-2.4.19/lib/searchlogic/named_scopes/association_ordering.rb:27:in `method_missing’ from /app/fd916ea6-bad5-440e-a560-405ef5e3beee/home/.bundle/gems/ruby/1.8/gems/searchlogic-2.4.19/lib/searchlogic/named_scopes/ordering.rb:30:in `method_missing’ from /app/fd916ea6-bad5-440e-a560-405ef5e3beee/home/.bundle/gems/ruby/1.8/gems/searchlogic-2.4.19/lib/searchlogic/named_scopes/or_conditions.rb:28:in `method_missing’ from /app/fd916ea6-bad5-440e-a560-405ef5e3beee/home/.bundle/gems/ruby/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:1994:in `method_missing’ from /app/fd916ea6-bad5-440e-a560-405ef5e3beee/home/app/models/ckeditor/attachment_file.rb:2 from /usr/ruby1.8.7/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require’ from /usr/ruby1.8.7/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require’ from /app/fd916ea6-bad5-440e-a560-405ef5e3beee/home/.bundle/gems/ruby/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:158:in `require’ from /app/fd916ea6-bad5-440e-a560-405ef5e3beee/home/.bundle/gems/ruby/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:265:in `require_or_load’ from /app/fd916ea6-bad5-440e-a560-405ef5e3beee/home/.bundle/gems/ruby/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:224:in `depend_on’ from /app/fd916ea6-bad5-440e-a560-405ef5e3beee/home/.bundle/gems/ruby/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:136:in `require_dependency’ from /app/fd916ea6-bad5-440e-a560-405ef5e3beee/home/.bundle/gems/ruby/1.8/gems/rails-2.3.8/lib/initializer.rb:414:in `load_application_classes’ from /app/fd916ea6-bad5-440e-a560-405ef5e3beee/home/.bundle/gems/ruby/1.8/gems/rails-2.3.8/lib/initializer.rb:413:in `each’ from […]

什么是最好使用 – rubygem或ruby插件

创建rails项目时的最佳做法是什么 1 – 使用ruby gems 2是否合适 – 或者使用ruby插件是否合适(因为几乎所有gem都有自己的插件版本) 每个选项的优点和缺点是什么? 考虑我们正在使用rails 2.xx或rails 3创建rails项目 提前致谢 欢呼声,同样的

Rails 3.0.0.beta和Facebooker:其他人看到以下内容?

安装facebooker插件后,我的rails服务器似乎破了。 任何有关解决这个问题的建议都会很棒。 我正在使用rails 3.0.0.beta和facebooker。 以下是我看到的步骤和错误: $ rails -v Rails 3.0.0.beta $ rails break; cd break $ ./script/rails plugin install git://github.com/mmangino/facebooker.git $ vim Rakefile #and add “require ‘tasks/facebooker'” $ ./script/rails server => Booting WEBrick => Rails 3.0.0.beta application starting in development on http://0.0.0.0:3000 => Call with -d to detach => Ctrl-C to shutdown server Exiting /Library/Ruby/Gems/1.8/gems/activesupport-3.0.0.beta/lib/active_support/dependencies.rb:456:in […]

将字符串标记为HTML安全

我正在尝试构建我的第一个Rails应用程序,并且我正在使用Ryan Heath的navigation_helper插件来为我提供导航中的当前类。 我按如下方式构建了我的命名路由: match ‘games’ => ‘games#index’, :as => :games match ‘new’ => ‘games#new’, :as => :new match ‘previous’ => ‘games#previous’, :as => :previous match ‘settings’ => ‘settings#index’, :as => :settings 然后在我的application_layout中添加了以下代码 根据我对Rails的了解,html_safe应该强制HTML正确呈现,但我得到的是: ["<li class=\"current\"><a href=\"/games\">Games</a></li>", "<li class=\"\"><a href=\"/new\">New</a></li>", "<li class=\"\"><a href=\"/previous\">Previous</a></li>", "<li class=\"\"><a href=\"/settings\">Settings</a></li>"] 我做错了什么或插件做错了什么? 我知道插件是在2.x天内写回来的,据我所知,处理HTML有点不同,但我还不够了解。