Ruby/Rails - Models Named with Two Words (Naming Convention Issues)
Your class should be singlular.
Name it PromotedEvent
in the file promoted_event.rb
a = PromotedEvent.new
Do rails MVC naming convention work with words which plural form is -ies (e.g. replies)?
I believe it internally relies on the pluralize method, so you can check in a rails console what is the result of a particular pluralisation :
"reply".pluralize
=> "replies"
So the answer to your question is yes ;)
Q about Ruby on Rails Naming Conventions
I believe some aspects of Rails will let you do what you wish (e.g., you can have an attribute start with an upper case letter rather than the generally assumed lower case), but it will be a lot more work for you if you deviate from their conventions. A lot of Rails framework functionality assumes the Rails convention and you might lose the ability to use some of those facilities. And then there are some I'm not sure there's a way to work around, like the naming of a file for a model (client_info.rb) versus the class inside (ClientInfo). Those are assumed to align.
My recommendation would be to learn the Rails way unless you want to live in your own Rails convention world, isolated from the rest of the Rails world. It bugged me too, at first, but I got used to it pretty quickly. :)
Rails 3 has_many :through naming issue
orders_products
is not the correct naming convention for a has_many :through
relationship--it is correct for a has_and_belongs_to_many
relationship. In a has_many :through
, the "join" model is not just for joining--it is also its own model that has its own data, that also happens to join two other models together.
If your OrderProduct
model doesn't have any of it's own data, logic, or constraints, then you could use a has_and_belongs_to_many
relationship instead, remove the model completely, and then your join table is named right. Otherwise, it is named according to regular model naming conventions, namely order_products
.
Rails unorthodox naming of models with abbreviations
Convention over configuration man. Suck it up.
What is a proper naming convention for related tables and models in rails 3
You might store different tables for investor_profiles
and advisor_profiles
with separate models InvestorProfile, AdvisorProfile
(which both might inherit from a base Profile
class, assuming they have at least a tiny bit of overlap).
But in your model associations, use the :class_name
option to hide the _profiles
:
class Investor < ActiveRecord::Base
has_one :profile, :class_name => "InvestorProfile"
end
class Advisor < ActiveRecord::Base
has_one :profile, :class_name => "AdvisorProfile"
end
# And since the profiles probably overlap in some way
# a profile base class which the other 2 profile classes extend
class Profile < ActiveRecord::Base
# base options like name, address, etc...
end
class InvestorProfile < Profile
# Investor-specific stuff
end
class AdvisorProfile < Profile
# Advisor-specific stuff
end
In practice then, you can refer to it as self.profile
:
# Use it as
adv = Advisor.new
puts adv.profile.inspect
See the ActiveRecord::Associations
documentation for descriptions of the options.
Model naming convention in Spine.js and Rails with two words
Ok, I should have kept looking: http://spinejs.com/docs/ajax. I found that you can override the default path by add @url option to the model.
class App.WorkRequest extends Spine.Model
@configure 'WorkRequest', ... [field list]
@extend Spine.Model.Ajax
@url: "/work_requests"
I'm still interested in the diference in naming conventions between Spine and Rails with multiword model names.
How to use two concerns with the same name?
I didn't find a way to use controller and model concerns with the same name without any namespaces.
So, my final solution is to use LikeableModel
and LikeableController
concerns.
Related Topics
Extract Links (Urls), with Nokogiri in Ruby, from a Href HTML Tags
How to Convert a JSON Formatted Key Value Pair to Ruby Hash with Symbol as Key
Rubocop: Line Is Too Long ← How to Ignore
How to Calculate the Offset, in Hours, of a Given Timezone from Utc in Ruby
Phusion Passenger Error: You Have Activated Rack 1.2.1, But Your Gemfile Requires Rack 1.2.2
Rails: Modifying a Model Generated by Scaffolding
Error Installing Homebrew - Brew Command Not Found
How to Convert a Comma-Separated String into an Array
Vagrant/Virtualbox Vm Provisioning: Rbenv Installs Successfully But Subsequent Uses in Script Fail
How to Pass a Custom Comparator to "Sort"
How to List the Currently Available Objects in the Current Scope in Ruby
Capybara: Select an Option by Value Not Text
How to Write a Web Scraper in Ruby
Undefined Method '>' for Nil:Nilclass <Nomethoderror>