is there an issue with underscores in table names ? I have 2 tables, events, event_types. each have a primary key of "id", and events has a foreign key named event_type_id. In event.rb i have a belongs_to :event_types in event_type.rb i have a has_many:events however when i try and do @ev_types = event_types.find_all in the events_controller.rb, i get an error when going to /events/ new... is this not allowed or am i missing something ? error is : undefined local variable or method `event_types'' for #<EventsController:0x408c7a5c> /app/controllers/events_controller.rb:18:in `new'' line 18 is this: @ev_types = event_types.find_all thanks adam _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Adam, I think you want to say ''EventType.find_all'' -Jeff Adam Denenberg wrote:> is there an issue with underscores in table names ? > > I have 2 tables, events, event_types. each have a primary key of > "id", and events has a foreign key named event_type_id. > > In event.rb i have a belongs_to :event_types > in event_type.rb i have a has_many:events > > however when i try and do > > @ev_types = event_types.find_all > > in the events_controller.rb, i get an error when going to > /events/new... is this not allowed or am i missing something ? > > error is : > > undefined local variable or method `event_types'' for > #<EventsController:0x408c7a5c> > > /app/controllers/events_controller.rb:18:in `new'' > > line 18 is this: > > @ev_types = event_types.find_all > > > thanks > adam > > > >------------------------------------------------------------------------ > >_______________________________________________ >Rails mailing list >Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >http://lists.rubyonrails.org/mailman/listinfo/rails > >
thanks Jeff, that worked. So its, singular form, and remove all underscores? On Aug 17, 2005, at 4:21 PM, Jeff Casimir wrote:> Adam, > > I think you want to say ''EventType.find_all'' > > -Jeff > > Adam Denenberg wrote: > > >> is there an issue with underscores in table names ? >> >> I have 2 tables, events, event_types. each have a primary key of >> "id", and events has a foreign key named event_type_id. >> >> In event.rb i have a belongs_to :event_types >> in event_type.rb i have a has_many:events >> >> however when i try and do >> @ev_types = event_types.find_all >> in the events_controller.rb, i get an error when going to /events/ >> new... is this not allowed or am i missing something ? >> >> error is : >> >> undefined local variable or method `event_types'' for >> #<EventsController:0x408c7a5c> >> >> /app/controllers/events_controller.rb:18:in `new'' >> >> line 18 is this: >> >> @ev_types = event_types.find_all >> >> >> thanks >> adam >> >> >> >> --------------------------------------------------------------------- >> --- >> >> _______________________________________________ >> Rails mailing list >> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >> http://lists.rubyonrails.org/mailman/listinfo/rails >> >> > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > >
Singular type, remove underscores *and* capitalise the first letter after the underscore event_types -> EventType fishing_trips -> FishingTrip Regards Dave M. On 8/18/05, Adam Denenberg <adam-fpx97dFL/ODYtjvyW6yDsg@public.gmane.org> wrote:> thanks Jeff, that worked. > > So its, singular form, and remove all underscores? > > > On Aug 17, 2005, at 4:21 PM, Jeff Casimir wrote: > > > Adam, > > > > I think you want to say ''EventType.find_all'' > > > > -Jeff > > > > Adam Denenberg wrote: > > > > > >> is there an issue with underscores in table names ? > >> > >> I have 2 tables, events, event_types. each have a primary key of > >> "id", and events has a foreign key named event_type_id. > >> > >> In event.rb i have a belongs_to :event_types > >> in event_type.rb i have a has_many:events > >> > >> however when i try and do > >> @ev_types = event_types.find_all > >> in the events_controller.rb, i get an error when going to /events/ > >> new... is this not allowed or am i missing something ? > >> > >> error is : > >> > >> undefined local variable or method `event_types'' for > >> #<EventsController:0x408c7a5c> > >> > >> /app/controllers/events_controller.rb:18:in `new'' > >> > >> line 18 is this: > >> > >> @ev_types = event_types.find_all > >> > >> > >> thanks > >> adam > >> > >> > >> > >> --------------------------------------------------------------------- > >> --- > >> > >> _______________________________________________ > >> Rails mailing list > >> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > >> http://lists.rubyonrails.org/mailman/listinfo/rails > >> > >> > > > > _______________________________________________ > > Rails mailing list > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Adam, When performing a find operation you are talking to the Model object, in your case EventType. And yes, models are camelcase with no underscores. The only time (that I can think of) when you use lower-case-and-underscores inside your rails app is to refer to controller/actions/methods. Good luck, Jeff Adam Denenberg wrote:> thanks Jeff, that worked. > > So its, singular form, and remove all underscores? > > > On Aug 17, 2005, at 4:21 PM, Jeff Casimir wrote: > >> Adam, >> >> I think you want to say ''EventType.find_all'' >> >> -Jeff >> >> Adam Denenberg wrote: >>