0

I am trying to get this model working with Strong Parameters but I can't seem to work out what I am doing wrong!?

ERROR:

Unknown key: name

Controller:

class PracticesController < ApplicationController

    def practice_params
        if params[:action] == 'create'
            params.require(:practice).permit( :name, :billing_address, :physical_address, :phone_number, :fax_number, :emergency_contact, :emergency_phone, :email_addres, :active, :ABN, :time_zone)
        elsif params[:action] == 'update'
            params.require(:practice).permit( :name, :billing_address, :physical_address, :phone_number, :fax_number, :emergency_contact, :emergency_phone, :email_addres, :active, :ABN, :time_zone)
        end
    end

    # GET /practices
  # GET /practices.json
  def index
    @practices = Practice.all

    respond_to do |format|
      format.html # index.html.erb
      format.json { render json: @practices }
    end
  end

  # GET /practices/1
  # GET /practices/1.json
  def show
    @practice = Practice.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.json { render json: @practice }
    end
  end

  # GET /practices/new
  # GET /practices/new.json
  def new
    @practice = Practice.new

    respond_to do |format|
      format.html # new.html.erb
      format.json { render json: @practice }
    end
  end

  # GET /practices/1/edit
  def edit
    @practice = Practice.find(params[:id])
  end

  # POST /practices
  # POST /practices.json
  def create
    @practice = Practice.new(practice_params)

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

  # PUT /practices/1
  # PUT /practices/1.json
  def update
    @practice = Practice.find(practice_params)

    respond_to do |format|
      if @practice.update_attributes(practice_params)
        format.html { redirect_to @practice, notice: 'Practice was successfully updated.' }
        format.json { head :ok }
      else
        format.html { render action: "edit" }
        format.json { render json: @practice.errors, status: :unprocessable_entity }
      end
    end
  end

  # DELETE /practices/1
  # DELETE /practices/1.json
  def destroy
    @practice = Practice.find(params[:id])
    @practice.destroy

    respond_to do |format|
      format.html { redirect_to practices_url }
      format.json { head :ok }
    end
  end
end

Model:

class Practice < ActiveRecord::Base
  #has_many :providers, :patients, :employees, :operatories, :clinics, :patients, 
  has_many :imagecategories
    validates_inclusion_of :time_zone, in: ActiveSupport::TimeZone.zones_map(&:name)

    def initial_setup
        Operatory.create(:name => "Default Operatory", :active => true, :practice => self)

        ####### Create Practice Basic Accounts:
        Revenue.create(:name => "General Revenue", :practice => self)

    end

end

Schema (relevant part of):

  create_table "practices", force: true do |t|
    t.string   "name"
    t.text     "billing_address"
    t.text     "physical_address"
    t.string   "phone_number"
    t.string   "fax_number"
    t.string   "emergency_contact"
    t.string   "emergency_phone"
    t.string   "email_address"
    t.boolean  "active"
    t.string   "ABN"
    t.datetime "created_at"
    t.datetime "updated_at"
    t.string   "time_zone"
  end

Any help getting this sorted out would be much appreciated, maybe I am tired and just missing something obvious. But I copied most of the code from other controllers that are working correctly andthink I have made all the necessary adjustments. Any help would be much appreciated

PS its not just limited to the :name parameter, when I remove that one it simply starts complaining about:billing_address

4

1 回答 1

1

在更新动作中,改变

@practice = Practice.find(practice_params)

@practice = Practice.find(params[:id])
于 2013-09-18T17:00:23.953 回答