English 中文(简体)
未经界定的“模型”方法:NilClass的名称: 在我数据库中试图制作记录时的级别
原标题:undefined method `model_name for NilClass:Class when trying to create a record in my database

我先看一下我的铁路。

When I try to create a new client in my clients table im getting this error => undefined method model_name for NilClass:Class

我要告诉我,错误在我看来是第2行。

1: <%- model_class = @client.class -%>
2: <h1><%=t  .title , :default => model_class.model_name.human %></h1>
3: 
4: <p>
5:   <strong><%= model_class.human_attribute_name(:name) %>:</strong><br>

我在这里表达了我的看法。

<%- model_class = @client.class -%>
<h1><%=t  .title , :default => model_class.model_name.human %></h1>

<p>
  <strong><%= model_class.human_attribute_name(:name) %>:</strong><br>
  <%= @client.name %>
</p>
<p>
  <strong><%= model_class.human_attribute_name(:detail) %>:</strong><br>
  <%= @client.detail %>
</p>
<p>
  <strong><%= model_class.human_attribute_name(:more_detail) %>:</strong><br>
  <%= @client.more_detail %>
</p>
<p>
  <strong><%= model_class.human_attribute_name(:more_details) %>:</strong><br>
  <%= @client.more_details %>
</p>

<div class="form-actions">
  <%= link_to t( .back , :default => t("helpers.links.back")),
              clients_path, :class =>  btn   %>
  <%= link_to t( .edit , :default => t("helpers.links.edit")),
              edit_client_path(@client), :class =>  btn  %>
  <%= link_to t( .destroy , :default => t("helpers.links.destroy")),
              client_path(@client),
              :method =>  delete ,
              :confirm => t( .confirm , :default => t("helpers.links.confirm", :default =>  Are you sure? )),
              :class =>  btn btn-danger  %>
</div>

这里是我的控制师 =>

班级客户 主计长兼主计长

  respond_to :html

  def index
    @clients = Client.all
    respond_with (@clients)
  end

  def new
    @clients = Client.new
    respond_with (@clients)
  end

  def create
    @clients = Client.new(params[:name])
    if @clients.save
      flash[:notice] = "Client successfully created"
    end
    respond_with(@clients)
  end

  def destroy
  @clients = Client.find(params[:id])
  @clients.destroy
  flash[:notice] = "Client has been removed."
  respond_with(@clients)
  end

end

我看不出问题在哪里?

不久前,我安装了铁丝网,但并不认为这将产生很大影响。

最佳回答

请在你的控制器中重新确定@clients(结尾处有s)的价值,并在您看来仅限在@client上查阅。 变量,即无<代码>s。 页: 1

问题回答

暂无回答




相关问题
rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

SSL slowness in EC2

We ve deployed our rails app to EC2. In our setup, we have two proxies on small instances behind round-robin DNS. These run nginx load balancers for a dynamically growing and shrinking farm of web ...

Auth-code with A-Za-z0-9 to use in an URL parameter

As part of a web application I need an auth-code to pass as a URL parameter. I am currently using (in Rails) : Digest::SHA1.hexdigest((object_id + rand(255)).to_s) Which provides long strings like : ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

activerecord has_many :through find with one sql call

I have a these 3 models: class User < ActiveRecord::Base has_many :permissions, :dependent => :destroy has_many :roles, :through => :permissions end class Permission < ActiveRecord::...

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

How to get SQL queries for each user where env is production

I’m developing an application dedicated to generate statistical reports, I would like that user after saving their stat report they save sql queries too. To do that I wrote the following module: ...

热门标签