Rails 3 迁移如何使用我的 ApplicationHelper 和 WidgetsHelper 中的方法?
我创建了一个迁移来重新格式化数据库中的一些内容(将格式为“my-name-city-state”的友好链接添加到我的商店记录中),但是 rake db:migrate
失败并且 说
undefined method `make_friendly_link' for #<ActiveRecord::ConnectionAdapters::SQLite3Adapter:0x3f90f30>
当我的迁移尝试访问 StoresHelper 中的 make_Friendly_link 方法时
。我尝试显式包含 ApplicationHelper 和 StoresHelper,但它仍然失败。
我的迁移是:
class FriendlyLinkForEveryone < ActiveRecord::Migration
include ModelHelper
include ApplicationHelper
include StoresHelper
def self.up
Store.find(:all).each do |store|
puts "STORE: #{store.name} #{store.city} #{store.state}"
if store.friendly_link.blank?
store.update_attributes :friendly_link => make_friendly_link(store.name, store.city, store.state)
end
end
end
def self.down
end
end
make_Friendly_link 方法位于我的stores_helper.rb 中,它调用我的application_helper.rb 中的方法
I've created a migration to reformat a few things in the database (adding a friendly link in format 'my-name-city-state' to my Stores records), but rake db:migrate
fails and says
undefined method `make_friendly_link' for #<ActiveRecord::ConnectionAdapters::SQLite3Adapter:0x3f90f30>
when my migration tries to access the method make_friendly_link in my StoresHelper.
I tried explicitly including the ApplicationHelper and StoresHelper, butit still fails.
My migration is:
class FriendlyLinkForEveryone < ActiveRecord::Migration
include ModelHelper
include ApplicationHelper
include StoresHelper
def self.up
Store.find(:all).each do |store|
puts "STORE: #{store.name} #{store.city} #{store.state}"
if store.friendly_link.blank?
store.update_attributes :friendly_link => make_friendly_link(store.name, store.city, store.state)
end
end
end
def self.down
end
end
The make_friendly_link method is in my stores_helper.rb and it calls a method in my application_helper.rb
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有点黑客,但你可以这样做:
Kind of hack, but you can do: