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 trial

Ruby

Daniel Cardenas
PLUS
Daniel Cardenas
Courses Plus Student 9,236 Points

undefined method `name'

Im on Building a simple ruby application--getting the latest section. And I keep getting this error when clicking on the button "Post a new status"

Any thoughts? here is the link to what i mean http://localhost:3000/statuses/new

Thanks, :)

3 Answers

Christopher Davis
Christopher Davis
13,738 Points

Could you include the code for your status controller, model, and the form view?

Daniel Cardenas
PLUS
Daniel Cardenas
Courses Plus Student 9,236 Points

class StatusesController < ApplicationController before_action :set_status, only: [:show, :edit, :update, :destroy]

# GET /statuses # GET /statuses.json def index @statuses = Status.all end

# GET /statuses/1 # GET /statuses/1.json def show end

# GET /statuses/new def new @status = Status.new end

# GET /statuses/1/edit def edit end

# POST /statuses # POST /statuses.json def create @status = Status.new(status_params)

respond_to do |format|
  if @status.save
    format.html { redirect_to @status, notice: 'Status was successfully created.' }
    format.json { render action: 'show', status: :created, location: @status }
  else
    format.html { render action: 'new' }
    format.json { render json: @status.errors, status: :unprocessable_entity }
  end
end

end

# PATCH/PUT /statuses/1 # PATCH/PUT /statuses/1.json 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 format.html { render action: 'edit' } format.json { render json: @status.errors, status: :unprocessable_entity } end end end

# DELETE /statuses/1 # DELETE /statuses/1.json def destroy @status.destroy respond_to do |format| format.html { redirect_to statuses_url } format.json { head :no_content } end end

private # Use callbacks to share common setup or constraints between actions. def set_status @status = Status.find(params[:id]) end

# Never trust parameters from the scary internet, only allow the white list through.
def status_params
  params.require(:status).permit(:name, :content)
end

end


class User < ActiveRecord::Base # Include default devise modules. Others available are: # :confirmable, :lockable, :timeoutable and :omniauthable devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable

Setup accesible (or protected) attributes for your model

attr_accessible :email, :password, :password_confirmation, :remember_me, :first_name, :last_name, :profile_name

end


<%= form_for(@status) do |f| %> <% if @status.errors.any? %> <div id="error_explanation"> <h2><%= pluralize(@status.errors.count, "error") %> prohibited this status from being saved:</h2>

  <ul>
  <% @status.errors.full_messages.each do |msg| %>
    <li><%= msg %></li>
  <% end %>
  </ul>
</div>

<% end %>

<div class="field"> <%= f.label :name %><br> <%= f.text_field :name %> </div> <div class="field"> <%= f.label :content %><br> <%= f.text_area :content %> </div> <div class="actions"> <%= f.submit %> </div> <% end %>

Thanks for the help in advance :)