Here I Just started to learn Ruby on Rails! My issues is when reading the data using my controller pages. I initiate my controller using this command rails g controller schoolTypes I then initiate my model has the following command rails g model schoolType Once this is done i then modify has follow the following pages create_school_type class CreateSchoolTypes < ActiveRecord::Migration def change create_table :school_types do |t| t.integer :schoolTypeID t.string :name t.description :text t.timestamps end end end did a rake db:migrate Change the following page school_types_controller.rb class SchoolTypesController < ApplicationController def index @schoolTypes = schooltype.all end def show end def new end def create end def update end def destroy end def edit end end index.html.erb <h1>School Types</h1> <% @schoolTypes.each do |schoolType|%> <%= schoolTypes.name %> <% end %> If I go to the following page http://localhost:3000/school_types I get the following errors undefined local variable or method `schooltype'' for #<SchoolTypesController:0xa9cd600> Any reason why? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en-US.
your model should call ''SchoolType'' and it''s in file app/models/school_type.rb then you should use @types = SchoolType.all (case sensitive) tom On Jul 9, 2012, at 21:13 , Jean-Sébastien D. wrote:> Here I Just started to learn Ruby on Rails! My issues is when reading > the data using my controller pages. > > I initiate my controller using this command > > rails g controller schoolTypes > > I then initiate my model has the following command > > rails g model schoolType > > Once this is done i then modify has follow the following pages > > create_school_type > class CreateSchoolTypes < ActiveRecord::Migration > def change > create_table :school_types do |t| > t.integer :schoolTypeID > t.string :name > t.description :text > > t.timestamps > end > end > end > did a rake db:migrate > > Change the following page > > school_types_controller.rb > class SchoolTypesController < ApplicationController > def index > @schoolTypes = schooltype.all > end > def show > end > def new > end > def create > end > def update > end > def destroy > end > def edit > end > end > > index.html.erb > <h1>School Types</h1> > <% @schoolTypes.each do |schoolType|%> > <%= schoolTypes.name %> > <% end %> > If I go to the following page http://localhost:3000/school_types I get > the following errors > undefined local variable or method `schooltype'' for > #<SchoolTypesController:0xa9cd600> > > Any reason why? > > -- > Posted via http://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en-US.-- ==============================================================================Tomas Meinlschmidt, MS {MCT, MCP+I, MCSE, AER}, NetApp Filer/NetCache www.meinlschmidt.com www.maxwellrender.cz www.lightgems.cz ============================================================================== -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en-US.
On 9 July 2012 20:13, Jean-Sébastien D. <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Here I Just started to learn Ruby on Rails! My issues is when reading > the data using my controller pages. > > I initiate my controller using this command > > rails g controller schoolTypes > > I then initiate my model has the following command > > rails g model schoolType > > Once this is done i then modify has follow the following pages > > create_school_type > class CreateSchoolTypes < ActiveRecord::Migration > def change > create_table :school_types do |t| > t.integer :schoolTypeIDYou don''t need this as an id field will automatically be added. Also life will be simpler if you stick to the rails conventions for naming things (don''t use camelCase), if you needed a school type id it should be called school_type_id. I suggest you work right through some tutorials on RoR in order to get the basic principles. railstutorial.org is good and is free to use online (how many times have I typed that in the last year I wonder, my fingers type it without conscious brain involvement). Also have a look at the Rails Guides, starting with Getting Started, obviously. Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en-US.
Rails uses four naming conventions for throughout it''s code which need to be followed by the developer (you) for their code to fit with Rails. These involve selective use or* singular* and *plural *together with *camelize*and *underscore*. The simplest way to demonstrate the conventional use is to run: *rails generate scaffold your_new_object name:string description:text size:integer* Then look at the model/view/controller files for uses of the variants on * your_new_object your_new_object your_new_objects YourNewObject YourNewObjects *If you''re running on a unix system (any Linux or OSX) this command will find them all when run within your application directory: *find . -name \*.rb -exec grep your_new {} \; -a -exec grep YourNew {} \; -a -print* Rick On Monday, July 9, 2012 3:13:02 PM UTC-4, Ruby-Forum.com User wrote:> > Here I Just started to learn Ruby on Rails! My issues is when reading > the data using my controller pages. > > I initiate my controller using this command > > rails g controller schoolTypes > > I then initiate my model has the following command > > rails g model schoolType > > Once this is done i then modify has follow the following pages > > create_school_type > class CreateSchoolTypes < ActiveRecord::Migration > def change > create_table :school_types do |t| > t.integer :schoolTypeID > t.string :name > t.description :text > > t.timestamps > end > end > end > did a rake db:migrate > > Change the following page > > school_types_controller.rb > class SchoolTypesController < ApplicationController > def index > @schoolTypes = schooltype.all > end > def show > end > def new > end > def create > end > def update > end > def destroy > end > def edit > end > end > > index.html.erb > <h1>School Types</h1> > <% @schoolTypes.each do |schoolType|%> > <%= schoolTypes.name %> > <% end %> > If I go to the following page http://localhost:3000/school_types I get > the following errors > undefined local variable or method `schooltype'' for > #<SchoolTypesController:0xa9cd600> > > Any reason why? > > -- > Posted via http://www.ruby-forum.com/. >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/oFDQCqjw9N0J. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en-US.
Thanks it works, it just get confusing with the singular and plurial -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en-US.