Ruby on Rails "uninitialized constant" error -
i creating application tracks customers quotes. customer has many quotes , 1 belongs 1 customer. trying use method combines first name , last name fields produce full name. code follows.
customer model:
class customer < activerecord::base has_many :quotes def full_name "#{fname} #{lname}" end end
quotes form.html.erb
<div class="field"> <%= f.label :customer_name %><br> <%= collection_select :quote, :customer_id, customer.all, :id, :full_name, {}, {:multiple => true} %> </div>
when try create new record, given "uninitialized constant customer::fname" error. please advise?
in ruby identifier begins uppercase letter constant.
irb(main):001:0> foo = 'bar' => "bar" irb(main):002:0> foo = 'baz' (irb):2: warning: initialized constant foo (irb):1: warning: previous definition of foo here => "baz" irb(main):003:0>
so class names constants written in camelcase (ghostwriter
) , attributes , methods commonly written in snake_case
.
actual constants written uppercase.
so bring together
class square # class name square constant sides = 4 # constant attr_accessor :height attr_accessor :width attr_accessor :background_color # attributes written in snakecase def area @height * width end def get_point # method names. end end
Comments
Post a Comment