I am new Ruby on Rails, so excuse me if my question seems pretty obvious. I am trying to validate uniqueness of a filed: class EventType < ActiveRecord::Base belongs_to :sport validates_uniqueness_of :event_type end When I run it, I get this error message: Showing /event_type/new.rhtml where line #27 raised undefined method `each'' for nil:NilClass <select name="event_type[sport_id]"> 27: <% @sports.each do |sport| %> 28: <option value="<%= sport.id %>" 29: <%= '' selected'' if sport.id == @event_type.sport.id %>> 30: <%= sport.sport %> However, if I take validates_uniqueness_of off, i.e.: class EventType < ActiveRecord::Base belongs_to :sport end everything works just fine. What am I doing wrong? Thank you, eduard
What do you have in your event_type controller (action new)? You do have @sports defined there, don''t you? //jarkko On 10.3.2005, at 05:32, TRIResults.com wrote:> I am new Ruby on Rails, so excuse me if my question seems pretty > obvious. > > I am trying to validate uniqueness of a filed: > > class EventType < ActiveRecord::Base > > belongs_to :sport > validates_uniqueness_of :event_type > > end > > When I run it, I get this error message: > Showing /event_type/new.rhtml where line #27 raised undefined method > `each'' for nil:NilClass > > <select name="event_type[sport_id]"> > 27: <% @sports.each do |sport| %> > 28: <option value="<%= sport.id %>" > 29: <%= '' selected'' if sport.id == @event_type.sport.id %>> > 30: <%= sport.sport %> > > However, if I take validates_uniqueness_of off, i.e.: > > class EventType < ActiveRecord::Base > > belongs_to :sport > > end > > everything works just fine. > > What am I doing wrong? > > Thank you, > eduard > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Jarkko Laine http://jlaine.net http://odesign.fi _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
yes, it''s defined: class EventTypeController < ApplicationController layout "standard-layout" scaffold :event_type def new @event_type = EventType.new @sports = Sport.find_all end end It''s strange, I only get an error if I try to validate event_type. It works fine with no validations. Thanks, eduard On Thu, 10 Mar 2005 09:39:22 +0200, Jarkko Laine <jarkko-k1O+Gnc6WpmsTnJN9+BGXg@public.gmane.org> wrote:> What do you have in your event_type controller (action new)? You do > have @sports defined there, don''t you? > > //jarkko > > On 10.3.2005, at 05:32, TRIResults.com wrote: > > > I am new Ruby on Rails, so excuse me if my question seems pretty > > obvious. > > > > I am trying to validate uniqueness of a filed: > > > > class EventType < ActiveRecord::Base > > > > belongs_to :sport > > validates_uniqueness_of :event_type > > > > end > > > > When I run it, I get this error message: > > Showing /event_type/new.rhtml where line #27 raised undefined method > > `each'' for nil:NilClass > > > > <select name="event_type[sport_id]"> > > 27: <% @sports.each do |sport| %> > > 28: <option value="<%= sport.id %>" > > 29: <%= '' selected'' if sport.id == @event_type.sport.id %>> > > 30: <%= sport.sport %> > > > > However, if I take validates_uniqueness_of off, i.e.: > > > > class EventType < ActiveRecord::Base > > > > belongs_to :sport > > > > end > > > > everything works just fine. > > > > What am I doing wrong? > > > > Thank you, > > eduard > > _______________________________________________ > > Rails mailing list > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > -- > Jarkko Laine > http://jlaine.net > http://odesign.fi > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > > >-- Eduard Sherstnev TRIResults.com
Possibly Parallel Threads
- routes.rb question.
- [ win32utils-Bugs-5285 ] event_type is not recognized properly
- Model studies in one analysis using treatment as a five level moderator in a meta-regression
- Model studies in one analysis using treatment as a five level moderator in a meta-regression
- Model studies in one analysis using treatment as a five level moderator in a meta-regression