开发者

how can a rails 3 migration use methods in my ApplicationHelper and WidgetsHelper?

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::M开发者_StackOverflowigration
  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


Kind of hack, but you can do:

v = ActionView::Base.new
v.make_friendly_link(store.name, store.city, store.state)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜