Rails 3.1,validates_presence_of =>错误NoMethodError:未定义的方法`bytesize':dager_fra:Symbol

时间:2011-06-14 13:43:12

标签: ruby-on-rails ruby-on-rails-3 ruby-on-rails-3.1

我有一个ajax表格:

_form.html.erb:

<%= form_for @innmelding, :remote => true, :html => { :id => 'kurs-form' } do |f| %>

innmeldings_controller.rb:

def create
  @innmelding = Innmelding.new( params[:innmelding] )
  flash[:notice] = "Lagret" if @innmelding.save
  respond_with( @innmelding, :layout => !request.xhr? )
end

innmelding.rb:

class Innmelding < ActiveRecord::Base      
  belongs_to :laerer, :foreign_key => "ansvarlig"
  belongs_to :laerer, :foreign_key => "overordnet"
  has_many :kurss
  validates_presence_of :dager_fra
end

的Gemfile:

source 'http://rubygems.org'
gem 'rails', '3.1.0.rc4'

gem 'sqlite3'
gem 'mysql2'

gem 'sass'
gem 'coffee-script'
gem 'coffeebeans'    
gem 'uglifier'

gem 'jquery-rails'

gem 'devise'
gem 'cancan'
gem 'haml'
gem 'event-calendar', :require => 'event_calendar'
gem 'therubyracer'

当“dager_fra”字段为空时,我收到以下错误:

“错误NoMethodError:未定义的方法`bytesize'代表:dager_fra:符号”

我正在使用rails 3.1-rc4(rc1上的相同错误)和ruby 1.9.2。我怀疑它与ruby 1.9有关。还没有设法让它在ruby 1.8上运行,所以我还没有验证这一点(想想我读了一些字节化方法从某些版本的轨道移出的地方,因为它现在是Ruby 1.9的一部分)。

1 个答案:

答案 0 :(得分:0)

这是rails问题,请查看此处https://github.com/rails/rails/issues/1730

尝试使用gemfile

gem'rails','3.1.0.rc4',: git =&gt; “https://github.com/rails/rails.git”,: branch =&gt; “3-1-稳定”

这帮助了我。