Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialcassac
9,628 PointsNoMethodError
NoMethodError in Statuses#new Showing C:/.../views/statuses/_form.html.erb where line #16 raised:
undefined method `Name' for #<Status:0x261b1d8> Extracted source (around line #16): 13 14 15 16 17 18 19
<div class="field">
<%= f.label :Name %><br>
<%= f.text_field :Name %>
</div>
<div class="field">
<%= f.label :content %><br>
Trace of template inclusion: app/views/statuses/new.html.erb
I'm assuming I accidentally deleted something? Any ideas?
Thanks =)
cassac
9,628 PointsThanks =)
5 Answers
Maxim Kontsevitch
25,447 PointsTry to write in your cmd: ``` rake db:migrate
Then try to change
Name to
name
Tell me if that helps :smiley:
cassac
9,628 PointsThanks for the quick response. Unfortunately the problem still persists after completing the above instructions.
Maxim Kontsevitch
25,447 PointsCan you please copy the output that shows on your cmd screen after you run rake db:migrate
?
Is there any output at all? If there isn't then try to run `rake
db:migrate RAILS_ENV =development
And show the output of that command/
Tell me if that helps.
cassac
9,628 PointsThere was no output for rake db: migrate. The output for rake db:migrate RAILS_ENV =development is:
rake db:migrate RAILS_ENV =development is "rake aborted. Don't know how to build task "RAILS_ENV". I then tried typing rake db:migrate RAILS_ENV=development (without the space between the equal symbol and "development") and there was no feedback.
Maxim Kontsevitch
25,447 PointsThat means your database is set. Try now and tell me how is it now.
cassac
9,628 PointsHmm, nothing was changed. I'm still receiving the error for "name" being an undefined method. I deleted the reference to "name" in "_form.html.erb", "index.html.erb" and "show.html.erb" and the problem went away. Does that provide any relevant clues?
cassac
9,628 PointsTo be more specific from the "_form.html.erb" file I deleted:
<div class="field"> <%= f.label :name %><br> <%= f.text_field :name %> </div>
From both the "index.html.erb" and "show.html.erb" files I deleted:
<p><%= status.content %></p>
Those were the references when deleted they allowed the application to work "properly."
Maxim Kontsevitch
25,447 PointsTry to add in your app/models/status.rb:
belongs_to :name ```
Then try to return the reference to "name".
Does that give you any issue?
cassac
9,628 PointsGreat, that fixed the problem. Now a NameError occurs whenever I edit/update or create a status.
The First Error
NameError in StatusesController#create uninitialized constant Status::Name
Extracted source (around line #27): 25 26 27 28 29 30
# POST /statuses.json def create @status = Status.new(status_params)
respond_to do |format|
if @status.save
Rails.root: C:/Users/.../treebook
Application Trace | Framework Trace | Full Trace app/controllers/statuses_controller.rb:27:in `create' Request
Parameters:
{"utf8"=>"?", "authenticity_token"=>"jtmv+so7KiX6x3YgfHoyCLuiL9SVNCRzZHIxRRDN8L8=", "status"=>{"name"=>"asdf", "content"=>"asdf"}, "commit"=>"Create Status"}
The Second Error
NameError in StatusesController#update uninitialized constant Status::Name
Extracted source (around line #44): 42 43 44 45 46 47
def update respond_to do |format| if @status.update(status_params) format.html { redirect_to @status, notice: 'Status was successfully updated.' } format.json { head :no_content } else
Rails.root: C:/Users/.../treebook
Application Trace | Framework Trace | Full Trace
app/controllers/statuses_controller.rb:44:in block in update'
app/controllers/statuses_controller.rb:43:in
update'
Request
Parameters:
{"utf8"=>"?", "_method"=>"patch", "authenticity_token"=>"jtmv+so7KiX6x3YgfHoyCLuiL9SVNCRzZHIxRRDN8L8=", "status"=>{"name"=>"", "content"=>"hello"}, "commit"=>"Update Status", "id"=>"7"}
I followed along the instructions from the video and even re watched most of them. How does something go wrong like this?
Enrico Kunz
6,456 PointsHaving the same problem! Could you please share the results over here if you figure out how to do it? Thanks for any hints!!
Enrico Kunz
6,456 PointsI guess these guys over here figured it out https://teamtreehouse.com/forum/nomethoderror-in-statusesnew-after-installing-devise-and-setting-up-sign-up-page -worked for me
cassac
9,628 PointsI'm confused because in my db>migrate directory I don't have the file 20140220055902_add_devise_to_users.rb instead I have 20140517063951_add_user_id_to_statuses.rb, 20140515084220_create_statuses.rb, and 20140517044837_devise_create_users.rb.
Maxim Kontsevitch
25,447 PointsChad You don't have that file because that file is from the "Adding the authentication system" Stage.
Hope that helps
cassac
9,628 PointsOK, so I backtracked a little bit and discovered I hadn't added "attr_accessible :content, :user_id" to the app\models\status.rb as instructed during the Simple Forms installation. The reason I didn't install it is because I was receiving an error having to do with the "attr_accessible". I then added "gem 'protected_attributes'" to my gem files, ran "bundle install“ in the console and the error disappeared.
Maxim Kontsevitch
25,447 PointsGreat, happy you solved it. Note: if you will use rails 3.2.6 you would not have any problems with protected attributes.
Maxim Kontsevitch
25,447 PointsMaxim Kontsevitch
25,447 PointsHey chad, can you show me a link to your whole project via github? Thank in advance