1

我收到了这个奇怪的错误,好像 SimpleForm 甚至没有安装:

undefined method `simple_form_for'

SimpleForm IS 在我的 gemfile 中,我已经安装了:

Using simple_form (2.0.2)

我在 Pow 服务器上运行,所以它每次都会重新启动。

#events_controller.rb
class admin::EventsController < ApplicationController
  def new
    @event = Event.new
  end

#Event.rb
class Event
  include Mongoid::Document
  field :summary
  field :start_date
  field :end_date
end

#new.html.haml
= simple_form_for [:admin, @event] do |f|
  = f.input :summary
  = f.input :start_date
  = f.input :end_date

任何想法为什么看起来 SimpleForm 甚至没有安装?

4

2 回答 2

1

安装 gem 后是否运行了生成器?在您的控制台中,您需要运行以下命令:

rails generate simple_form:install
于 2012-09-27T23:19:30.897 回答
0

我尝试了命令: rails generate simple_form:install

而且 - 它没有运行。相反,输出看起来像是我给 rails 一个格式错误的命令行,它返回了一个使用文件的副本。

然后,在 RubyMine 中,我再次尝试了 - 这次得到了错误回溯 - 第一行如下所示:

/home/user1/.rvm/gems/ruby-2.0.0-p247/gems/railties-4.0.0/lib/rails/generators/base.rb:265:in `const_defined?': wrong constant name SimpleForm:installGenerator 

注释掉 base.rb 中的第 265-269 行后:

#  if last && last.const_defined?(last_name.camelize, false)
#     raise Error, "The name '#{class_name}' is either already used in your application " <<
#            "or reserved by Ruby on Rails. Please choose an alternative and run "  <<
#            "this generator again."
#  end

再次运行命令,我得到:

/home/user1/.rvm/rubies/ruby-2.0.0-p247/bin/ruby -e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift) /home/user1/RubymineProjects/TravelAid/bin/rails generate generator simple_form:install -s
      create  lib/generators/simple_form:install
      create  lib/generators/simple_form:install/simple_form:install_generator.rb
      create  lib/generators/simple_form:install/USAGE
      create  lib/generators/simple_form:install/templates

Process finished with exit code 0

这看起来不错,但我还没有回去检查 simple_form 是否有效。

在 lib/generators 下,我有:

simple_form
  templates
  simple_form_generator.rb
  USAGE
simple_form.install
  templates
  simple_form.install_generator.rb  (created about 18 minutes ago - consistent with new)
  USAGE

我在 Rubymine 中运行 Rails 4.0.0 和 ruby​​-2.0.0-p247

于 2013-07-09T06:40:42.823 回答