定义SimpleForm和rails的操作

时间:2012-09-27 23:10:02

标签: ruby-on-rails simple-form

我收到了这个奇怪的错误,就好像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似乎没有安装?

2 个答案:

答案 0 :(得分:1)

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

rails generate simple_form:install

答案 1 :(得分:0)

我尝试了这个命令: rails生成simple_form:install

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

然后,在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