NameError in GenresController#index
uninitialized constant GenresController
RAILS_ROOT: C:/Users/Will/Desktop/INSTAN~1/rails_apps/talewiki
I've created a table called Genres and when I try to connect to it via local host I get the above error.
Any ideas?
With all the questions you're asking I believe you're an absolute beginner regarding ROR. Perhaps you should visit some tutorials to learn rails.
I don't know what your genre model describes, but I think it will have a name.
Basic steps for a basic genre model:
Delete the table for your genres if created manually (with SQL code)
DROP TABLE genres;
generate a complete scaffolding for genres:
$ ruby script/generate genre name:string
$ rake db:migrate
Now you have a complete controller for all CRUD actions for a simple genre model
If I were you I would read some tutorial about RoR, because you make the impression that you don't understand RoR or the MVC principle behind it. A good start would be: http://storecrowd.com/blog/top-50-ruby-on-rails-tutorials/
You need to generate a controller to handle the index action when your browse your application on localhost
ruby script/generate controller genres index
run that from your console within your application and it will generate the GenresController with the action index (it will be an empty action but you shouldn't see an error when browsing http://localhost:3000/genres/)
file
C:/Users/Will/Desktop/INSTAN~1/rails_apps/talewiki/app/controllers/genres_controller.rb
must be present
Related
I have just created the project on ruby on rails. I also generated a controller with an instruction on bash, "rails g controller home".
However, I didn't make database. How can I generate database? Please inform me how to make database.
Thank you.
You can generate a database table by typing:
rails g model myTableName
Because your starting out new i think it would be best to try something like:
rails g scaffold Post name:string content:text
This will link the controller, the model(which is the database) and the views together, giving you a better understanding on how the MVC structure works in rails.
I've just started programming using Instant rails and don't know much about it. So, I've made a rails project and created a database name contactlist_development and a table named contacts with some fields. I've generated a model named Contact and started the rails console using "ruby script/console".
But when i tried making a new Contact model object, it displays StatementInvalid : could not find the table 'contacts'.
Running rake db:migrate will execute the code you generated, hence creating the table.
Hope this helps!
Have you used rails generate model contact command to make Contact model? If yes, you forget to run command :
rake db:migrate
Or you can make table directly by creating migration or using sql query.
I'm running rails v 3.2 .
After some time developing application I need to move some models into namespace ex: /app/models/address.rb to /app/models/local/address.rb
I tried simply moving models to destination folder and adding Local:: to the class name. then i accordingly update specs, and i still get an error on running spec.he . uninitialized constant Address (NameError).
The question is - How can i move models to a namespace? what are my actions - editing migrations or something else... Please help because i got mixed up by different articles & etc.
Update
I found out what's the problem:
Devise and namespaces. solving it
I think you can try this:
create a new rails project, then run
rails g model Local::Address city:string country:string
Now you can see how rails handle namespace for model. You can just follow the way to modify yours.
On my blog I'm have posts that belong to a series. I've tried to scaffold series but there are some problems with routes.
The pluralization engine doesn't get it right so I had to manually change Sery, #series, and #sery which is not a big deal.
The routing seems to be ok with resources :series. But then when I try to create a series the form_for helper complains about the route.
And then when I create it with console it works but rails is still complaining about routes.
Please create a simple app and see what the problem is.
rails new test_series_app
And then run the scaffold generator:
rails g scaffold series name:string
And see how the routes are getting mixed up and help me out please!
For the record, I put the singularize code into the scaffold generator (yes, my one contribution to Rails). All it does is check if record_name == record_name.pluralize. If it does and you haven't passed in --force-plural, it calls record_name = record_name.singularize.
In this case "series".pluralize is the same as "series".singularize so I assume it won't do anything.
So if you're having problems w/ it, you need to write an inflector for the word.
(I wrote it after Jeremy Kemper's 2008 RailsConf keynote in which he accidentally passed in a plural model name causing himself all sorts of grief in the middle of his talk.)
Say I have the model CourseGroup. What would be the controller's name?
The controller name would be course_groups_controller.
http://itsignals.cascadia.com.au/?p=7
To find the name for any model, you can open up a rails console and do "ModelName".tableize. Then just add "_controller" to the end. This would result in model_names_controller.
Here's an easy way to find out the naming conventions: Just create a throw-away Rails app in a temp directory, with a scaffolded model:
rails blog
cd blog
./script/generate scaffold post subject:string content:text
You can then browse through the files and directories to see how things are named. I like to keep one of these around just to refer to from time to time. And by the way, running the generators without any parameters gives help output which includes examples of naming conventions:
./script/generate scaffold