Hi, I have just started using Ruby on Rails with cPanel. I can set up my application ok but I am having problems with linking the application with a mysql database. I have run ruby sctipt/generate model and created the table through the migration. The table appears in the database correctly. The original settings were for sqlite3 but I want to use mysql so that may be the issue. I have changed the database.yml file matching with the correct db information; development: adapter: mysql database: [hidden] username: [hidden] password: [hidden] host: localhost socket: /var/lib/mysql/mysql.sock I want to access a table from the db. In the team controller I do this (i have a table called teams); @team = Team.find(:all) and in the views do this; <% for player in @team %> <%= player.id %> <% end %> but I get this error; NoMethodError in Team#index Showing team/index.html.erb where line #4 raised: You have a nil object when you didn''t expect it! You might have expected an instance of Array. The error occurred while evaluating nil.each Extracted source (around line #4): 1: Team Says Hi 2: <br /><br /> 3: 4: <% for player in @team %> 5: <%= player.id %> 6: <% end %> 7: hope you can help. Thanks a lot -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
try executing following seems like your table is empty try follwoing open command window.. goto your project directory.. run console.. ./script/console they try Team.find(:all) and see if it returns anything.. it will tell you if there is any data in teams table. let me know Ajit On Oct 23, 7:30 am, Rob Pa <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Hi, > > I have just started using Ruby on Rails with cPanel. I can set up my > application ok but I am having problems with linking the application > with a mysql database. > > I have run ruby sctipt/generate model and created the table through the > migration. The table appears in the database correctly. > > The original settings were for sqlite3 but I want to use mysql so that > may be the issue. > > I have changed the database.yml file matching with the correct db > information; > development: > adapter: mysql > database: [hidden] > username: [hidden] > password: [hidden] > host: localhost > socket: /var/lib/mysql/mysql.sock > > I want to access a table from the db. > > In the team controller I do this (i have a table called teams); > > @team = Team.find(:all) > > and in the views do this; > > <% for player in @team %> > <%= player.id %> > <% end %> > > but I get this error; > > NoMethodError in Team#index > > Showing team/index.html.erb where line #4 raised: > > You have a nil object when you didn''t expect it! > You might have expected an instance of Array. > The error occurred while evaluating nil.each > > Extracted source (around line #4): > > 1: Team Says Hi > 2: <br /><br /> > 3: > 4: <% for player in @team %> > 5: <%= player.id %> > 6: <% end %> > 7: > > hope you can help. > > Thanks a lot > -- > Posted viahttp://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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi, Yep the data is shown which I had entered into the table, through the migration. Hope you can help, Thanks a lot! -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Seemingly Similar Threads
- any luck installing RoR with apache / cpanel setup?
- Installing ror on vps with cpanel
- RoR and problem with connection to MySQL database
- ActiveRecord::AssociationTypeMismatch in UsersController#update
- New RoR app: RTRails 0.1. Uses HTTP push and a window system