ruby on rails - NoMethodError in Clients#new -
so i'm getting error in 1 of views , seems have way client being initialized in controller, here's code client model , controller:
model:
class client < activerecord::base has_many :visits has_many :exchanges, through: :visits
controller:
class clientscontroller < applicationcontroller before_action :set_client, only: [:show, :edit, :update, :destroy] def index @clients = client.all end # /clients/new def new @client = client.new end # post /clients # post /clients.json def create @client = client.new(client_params) respond_to |format| if @client.save format.html { redirect_to @client, notice: 'client created.' } format.json { render action: 'show', status: :created, location: @client } else format.html { render action: 'new' } format.json { render json: @client.errors, status: :unprocessable_entity } end end end # patch/put /clients/1 # patch/put /clients/1.json def update respond_to |format| if @client.update(client_params) format.html { redirect_to @client, notice: 'client updated.' } format.json { head :no_content } else format.html { render action: 'edit' } format.json { render json: @client.errors, status: :unprocessable_entity } end end end # delete /clients/1 # delete /clients/1.json def destroy @client.destroy respond_to |format| format.html { redirect_to clients_url } format.json { head :no_content } end end private # use callbacks share common setup or constraints between actions. def set_client @client = client.find(params[:id]) end # never trust parameters scary internet, allow white list through. def client_params #hidden security end end
so error goes off @ line 1 client form when calls @client , says "undefined method `model_name' activerecord::relation::activerecord_relation_client:class" use have no idea going on, thanks.
error stack:
started "/clients/new" 127.0.0.1 @ 2014-04-06 14:05:48 -0400 processing clientscontroller#new html rendered clients/_form.html.erb (62.2ms) rendered clients/new.html.erb within layouts/application (65.3ms) completed 500 internal server error in 68ms actionview::template::error (undefined method `model_name' activerecord::relation::activerecord_relation_client:class): 1: <%= simple_form_for(@client) |f| %> 2: <% if @client.errors.any? %> 3: <div id="error_explanation"> 4: <h2><%= pluralize(@client.errors.count, "error") %> prohibited client being saved:</h2> app/views/clients/_form.html.erb:1:in `_app_views_clients__form_html_erb___2200324505640086965_70348410359440' app/views/clients/new.html.erb:3:in `_app_views_clients_new_html_erb___3059029162300151807_70348376263300' rendered /library/ruby/gems/2.0.0/gems/actionpack-4.0.4/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.6ms) rendered /library/ruby/gems/2.0.0/gems/actionpack-4.0.4/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (0.8ms) rendered /library/ruby/gems/2.0.0/gems/actionpack-4.0.4/lib/action_dispatch/middleware/templates/rescues/template_error.erb within rescues/layout (12.8ms)
Comments
Post a Comment