Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/61.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 定义SimpleForm和rails的操作_Ruby On Rails_Simple Form - Fatal编程技术网

Ruby on rails 定义SimpleForm和rails的操作

Ruby on rails 定义SimpleForm和rails的操作,ruby-on-rails,simple-form,Ruby On Rails,Simple Form,我遇到了一个奇怪的错误,好像SimpleForm甚至没有安装: undefined method `simple_form_for' Using simple_form (2.0.2) SimpleForm在我的GEM文件中,我已安装: undefined method `simple_form_for' Using simple_form (2.0.2) 我在Pow服务器上运行,所以每次都会重新启动 #events_controller.rb class admin::EventsCo

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

undefined method `simple_form_for'
Using simple_form (2.0.2)
SimpleForm在我的GEM文件中,我已安装:

undefined method `simple_form_for'
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
#events_controller.rb
类admin::EventsController

你知道为什么SimpleForm似乎没有安装吗?

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

rails generate simple_form:install

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

rails generate simple_form:install
我试过命令: rails生成简单表单:安装

而且,它没有运行。相反,输出看起来像是我给了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
这看起来不错,但我还没有回去检查simple_表单是否有效

在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

我尝试了以下命令: rails生成简单表单:安装

而且,它没有运行。相反,输出看起来像是我给了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
这看起来不错,但我还没有回去检查simple_表单是否有效

在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

如果您查看gem文档,简单表单取决于活动记录。比如这里。如果你正在使用Mongoid,也许可以尝试其他方法。是的,你肯定是对的,但我不知道这是否是实际问题,因为我认为基本功能在两者之间仍然有效。不管怎么说,我不知道该怎么做才行。所有这些文件看起来都完全相同。我在另一个制作脚手架的部门之间切换,试图回到基本面,当我切换回这个部门时,它就工作了。也许某个地方的随机配置把事情搞砸了?至少我没有把所有的头发都拔出来。如果你看看gem文档,简单的表单取决于活动记录。比如这里。如果你正在使用Mongoid,也许可以尝试其他方法。是的,你肯定是对的,但我不知道这是否是实际问题,因为我认为基本功能在两者之间仍然有效。不管怎么说,我不知道该怎么做才行。所有这些文件看起来都完全相同。我在另一个制作脚手架的部门之间切换,试图回到基本面,当我切换回这个部门时,它就工作了。也许某个地方的随机配置把事情搞砸了?至少我没有把头发都拔出来。