Rails 3.1, validates_presence_of => ERROR NoMethodError: undefined method `bytesize' for :dager_fra:Symbol
I have an ajax form:
_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'
When the "dager_fra" field is empty I get the following error:
"ERROR NoMethodError: undefined method `bytesize' for :dager_fra:Symbol"
I'm using rails 3.1-rc4 (same error on rc1), and ruby 1.9.2. I suspect it has something with r开发者_开发知识库uby 1.9. Haven't managed to get it running on ruby 1.8, so I haven't verified this (think I read some place that bytesize method is moved out of rails of some release because it's now part of Ruby 1.9).
This is rails issue, look here https://github.com/rails/rails/issues/1730
Try in your gemfile
gem 'rails', '3.1.0.rc4', :git => "https://github.com/rails/rails.git", :branch => "3-1-stable"
This helped me.
精彩评论