Question

Rails 4.1 Ruby 2.0 Windows 8.1

When I try to create a new hobbyist, I get the following error:

undefined method `organization' for #<Hobbyist:0x000000070d0ac8>

With the following additional error details:

    block in _app_views_hobbyists__form_html_erb__2100369257_59197480
    app/views/hobbyists/_form.html.erb, line 8
    _app_views_hobbyists__form_html_erb__2100369257_59197480
    app/views/hobbyists/_form.html.erb, line 1
    _app_views_hobbyists_new_html_erb__583593320_59167000
    app/views/hobbyists/new.html.erb, line 3

Any ideas:

This is the controller:

  class hobbyistsController < ApplicationController
  before_action :set_hobbyist, only: [:show, :edit, :update, :destroy]

  # GET /hobbyists
  # GET /hobbyists.json
  def index
    @hobbyists = hobbyist.all
  end

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

  # GET /hobbyists/new
  def new
    @hobbyist = hobbyist.new
  end

  # GET /hobbyists/1/edit
  def edit
  end

  # POST /hobbyists
  # POST /hobbyists.json
  def create
    @hobbyist = hobbyist.new(hobbyist_params)

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

  # PATCH/PUT /hobbyists/1
  # PATCH/PUT /hobbyists/1.json
  def update
    respond_to do |format|
      if @hobbyist.update(hobbyist_params)
        format.html { redirect_to @hobbyist, notice: 'hobbyist was successfully updated.' }
        format.json { render :show, status: :ok, location: @hobbyist }
      else
        format.html { render :edit }
        format.json { render json: @hobbyist.errors, status: :unprocessable_entity }
      end
    end
  end

  # DELETE /hobbyists/1
  # DELETE /hobbyists/1.json
  def destroy
    @hobbyist.destroy
    respond_to do |format|
      format.html { redirect_to hobbyists_url }
      format.json { head :no_content }
    end
  end

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

    # Never trust parameters from the scary internet, only allow the white list through.
    def hobbyist_params
      params.require(:hobbyist).permit(:first, :last, :salutation, :organization, :work_phone, :mobile_phone, :fax_phone, :other_phone, :address1, :address2, :city, :state, :zip)
    end
end

This is the hobbyist new view

<h1>New hobbyist</h1>

<%= render 'form' %> (THIS IS LINE 3)

<%= link_to 'Back', hobbyists_path %>

This is the hobbyist __form view

<%= simple_form_for(@hobbyist) do |f| %> (THIS IS LINE 1)
  <%= f.error_notification %>

  <div class="form-inputs">
    <%= f.input :first %>
    <%= f.input :last %>
    <%= f.input :salutation %>
    <%= f.input :organization %> (THIS IS LINE 8)
    <%= f.input :work_phone %>
    <%= f.input :mobile_phone %>
    <%= f.input :fax_phone %>
    <%= f.input :other_phone %>
    <%= f.input :address1 %>
    <%= f.input :address2 %>
    <%= f.input :city %>
    <%= f.input :state %>
    <%= f.input :zip %>
  </div>

  <div class="form-actions">
    <%= f.button :submit %>
  </div>
<% end %>
Was it helpful?

Solution

"organization" was missing from the table. I fixed the problem by adding a migration to include "organization". The lower case h in the question are a side effect of having used a "smart" editor to compose the question before posting stackoverflow.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top