Note that there are some explanatory texts on larger screens.

plurals
  1. POundefined method for new specified column
    primarykey
    data
    text
    <p>I had to create a new migration to add "feet" and "inches" to the profile page so that users can enter their height. I ran the command: </p> <blockquote> <p>rails generate migration AddFeetAndInchesToUsers feet:integer inches:integer</p> </blockquote> <p>thinking that would get it to work and it didn't. I am receiving the error message `</p> <blockquote> <p>"undefined method `feet' for #User:0x007fe41dbe9520"</p> </blockquote> <p>` when trying to view profile page.</p> <p>I have all the other fields working for my profile page as I have defined them in the user model previously by doing "rails g resource user then-all-my-options-here". But now I need to define feet, inches, religion and religion importance. I'm not understanding how to add to an existing model.</p> <p>I have added those values to the create_profiles.rb which is in the db folder. Added to profile.rb and user.rb. None of those work. I believe to fix it I need to somehow get it inside user.rb the proper way, as I only typed it into the attr_accessible and I'm sure to properly get "feet, options, and religion options" to work is to go through the terminal first.</p> <p>User.rb</p> <pre><code>class User &lt; ActiveRecord::Base has_secure_password attr_accessible :about_me, :feet, :inches, :password, :birthday, :career, :children, :education, :email, :ethnicity, :gender, :height, :name, :password_digest, :politics, :religion, :sexuality, :user_drink, :user_smoke, :username, :zip_code validates_uniqueness_of :email validates_presence_of :password, :on =&gt; :create before_create { generate_token(:auth_token) } def send_password_reset generate_token(:password_reset_token) self.password_reset_sent_at = Time.zone.now save! UserMailer.password_reset(self).deliver end def generate_token(column) begin self[column] = SecureRandom.urlsafe_base64 end while User.exists?(column =&gt; self[column]) end end </code></pre> <p>show.html.erb (profile page):</p> <pre><code>&lt;h1&gt;&lt;%= @user.username %&gt;&lt;/h1&gt; &lt;h2&gt;Basics&lt;/h2&gt; &lt;%= form_for @user do |f| %&gt; &lt;div class="field"&gt; &lt;%= f.label :height %&gt;&lt;br/&gt; &lt;%= f.select :feet, [['Feet', nil], '4', '5', '6'] %&gt; &lt;%= f.select :inches, [['Inches', nil], '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11'] %&gt; &lt;/div&gt; &lt;div class="field"&gt; &lt;%= f.label :children %&gt;&lt;br/&gt; &lt;%= f.select :children, [['Do you have or want kids?', nil], 'Yes, they live with me', 'I want kids now', 'I want one someday', 'Not for me']%&gt; &lt;/div&gt; &lt;div class="field"&gt; &lt;%= f.label :religion %&gt;&lt;br/&gt; &lt;%= f.select :religion, [['What is your faith?', nil], 'Agnostic', 'Atheist', 'Christian', 'Catholic', 'Buddhist', 'Hindu', 'Jewish', 'Muslim', 'Spiritual without affiliation', 'Other', 'None', 'Prefer not to say' ]%&gt;&lt;br/&gt; &lt;%= f.select :religion, [['How important is this to you?', nil], 'Very Important', 'Somewhat Important', 'Not Important']%&gt; &lt;/div&gt; &lt;div class="field"&gt; &lt;%= f.label :career %&gt;&lt;br/&gt; &lt;%= f.text_field :career %&gt; &lt;/div&gt; &lt;div class="field"&gt; &lt;%= f.label :education %&gt;&lt;br/&gt; &lt;%= f.select :education, [['What is your education level?', nil], 'High school', 'Some college', 'Undergraduate', "Bachelor's", "Master's ", 'PhD', 'Business school', 'Law school', 'Medical school' ]%&gt; &lt;/div&gt; &lt;div class="field"&gt; &lt;%= f.label :ethnicity %&gt;&lt;br/&gt; &lt;%= f.select :ethnicity, [['What is your ethnicity?', nil], 'Asian', 'Black', 'Biracial', 'Indian', 'Hispanic/Latin', 'Middle Eastern', 'Native American', 'Pacific Islander', 'White', 'Other' ]%&gt; &lt;/div&gt; &lt;%= f.label :user_drink %&gt;&lt;br/&gt; &lt;%= f.select :user_drink, [['How much do you drink?', nil], 'Often Drinks', 'Sometimes drinks', 'Never drinks', 'No comment' ]%&gt; &lt;/div&gt;&lt;br/&gt; &lt;%= f.label :user_smoke %&gt;&lt;br/&gt; &lt;%= f.select :user_smoke, [['How often do you smoke?', nil], 'Often smokes', 'Sometimes smokes', 'Never smokes'] %&gt; &lt;/div&gt; &lt;div class="actions"&gt;&lt;%= f.submit %&gt;&lt;/div&gt; &lt;h3&gt;About Me&lt;/h3&gt; &lt;%= form_for @user do |f| %&gt; &lt;div class="field"&gt; &lt;%= f.label :about_me %&gt;&lt;br/&gt; &lt;%= f.text_field :about_me %&gt; &lt;div class="actions"&gt;&lt;%= f.submit %&gt;&lt;/div&gt; &lt;% end %&gt; &lt;% end %&gt; </code></pre> <p>add_feet_and_inches_to_users.rb (this is in /db folder and was created after I ran the command posted on top of post):</p> <pre><code>class AddFeetAndInchesToUsers &lt; ActiveRecord::Migration def change add_column :users, :feet, :integer add_column :users, :inches, :integer end end </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload