This is really a question about naming conventions.
I have a model called PromotedEvents
The file is called promoted_events.rb
I created the table with:
create_table :promoted_events do |t|
Now I'm having problems creating anything, so I'm wondering if theres some problem using model with two words
im in the console and tried
a = PromotedEvents.new a = Promoted_Event.new a = promoted_event.new
and keep getting a nameerror : uninitialized constant
error
Any ideas?
Naming conventions in Active Record model Rails is capable of pluralizing (and singularizing) both regular and irregular words. Model class names must use the CamelCase form when composed of two or more words, while the database table names must use the snake_case form.
Variable names in Ruby can be created from alphanumeric characters and the underscore _ character. A variable cannot begin with a number. This makes it easier for the interpreter to distinguish a literal number from a variable. Variable names cannot begin with a capital letter.
Controller class names use CamelCase and have Controller as a suffix. The Controller suffix is always singular. The name of the resource is usually plural. Controller actions use snake_case and usually match the standard route names Rails defines ( index , show , new , create , edit , update , delete ).
A Rails Model is a Ruby class that can add database records (think of whole rows in an Excel table), find particular data you're looking for, update that data, or remove data.
Your class should be singlular.
Name it PromotedEvent
in the file promoted_event.rb
a = PromotedEvent.new
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With