Ruby on rails 链接\u以编辑页面默认路径?

Ruby on rails 链接\u以编辑页面默认路径?,ruby-on-rails,Ruby On Rails,我正在使用Rails3构建一个简单的客户信息页面(表格式)。在此页面上,用户可以编辑每个客户的详细信息。每个客户都可能有多个记录。我使用link_进入编辑页面: <td class="edit" id="edit">edit <%= link_to 'edit', :action => :edit, :cust_id => ci.cust_id %> </td> 客户信息页面显示右侧。单击“编辑”链接时,我收到错误消息: ActionView::

我正在使用Rails3构建一个简单的客户信息页面(表格式)。在此页面上,用户可以编辑每个客户的详细信息。每个客户都可能有多个记录。我使用link_进入编辑页面:

<td class="edit" id="edit">edit
<%= link_to 'edit', :action => :edit, :cust_id => ci.cust_id %>
</td>
客户信息页面显示右侧。单击“编辑”链接时,我收到错误消息:

ActionView::Template::Error (undefined method `cust_info_cust_info_path' for #<#<Class:0x7fb0857ce7b8>:0x7fb0857ca780>):
    1: <h1>Editing cust</h1>
    2: 
    3: <%= form_for(@cust_info) do |cust| %>
    4:  Customer: <%= cust.text_field :cust_schema %>
    5:  <%= cust.submit "Save" %>
    6: <% end%>
  app/views/track/edit.html.erb:3:in `_app_views_track_edit_html_erb___102324197_70198065248580_0'
ActionView::Template::Error(未定义的方法'cust_info_cust_info_path'):
1:编辑客户
2: 
三:
4:客户:
5:  
6: 
app/views/track/edit.html.erb:3:在“app\u views\u track\u edit\u html\u erb\u 102324197\u 70198065248580\u 0”中
“客户信息”来自哪里

编辑:以下是控制器中的代码:

class TrackController < ApplicationController

def display
end

def information
end


def customerinfo
    @cust_info = CustInfo.find(:all, :order=>"cust_id")
    @cust_info.each do |ci|
                    if ci.upload_freq == 'W'
                            ci.upload_freq = 'Weekly'
                    elsif ci.upload_freq == 'M'
                            ci.upload_freq = 'Monthly'
                    end

    end

end


def edit
    cust_id = params[:cust_id]
    @cust_info = CustInfo.find(:all, :conditions => ["cust_id = ?", cust_id])

end 
class TrackController“cust\u id”)
@客户信息。每个do|ci|
如果ci.upload_freq=='W'
ci.upload_freq=‘每周’
elsif ci.upload_freq=='M'
ci.upload_freq=‘每月’
终止
终止
终止
定义编辑
客户id=参数[:客户id]
@cust_info=CustInfo.find(:all,:conditions=>[“cust_id=?”,cust_id])
终止
结束
结束更改
@cust\u info=CustInfo.find(:all,:conditions=>[“cust\u id=?”,cust\u id])


@cust\u info=CustInfo.find(cust\u id)
Change
@cust\u info=CustInfo.find(:all,:conditions=>[“cust\u id=?”,cust\u id])


@cust\u info=CustInfo.find(cust\u id)

您这样做的原因是什么?我以前确实试过。我得到了一个错误:NoMethodError(未定义的方法
eq',用于nil:NilClass):app/controllers/track\u controller.rb:163:in
edit'。我认为这两种方法都应该有效,但我还没有弄清楚为什么会出现这个错误。
find(:all)
将返回一个数组
find(id)
将返回与该id匹配的对象,或
nil
。您必须发布
track\u controller.rb
的内容,以便更深入地了解如何处理下一组错误。此行不再有错误。实际上,
find(id)
不会返回
nil
,如果顾名思义,没有找到记录,它将返回
RecordNotFound
错误。如果希望它返回
nil
而不是
RecordNotFound
,则需要执行
findby\u id(id)
。我明白了。这是有道理的。然而,在这种情况下,它不应该返回nil。我看到了日志,当我使用find(:all,:condition=>cust\u id=cust\u id)时,实际上返回了一些项目。我将把我的控制器逻辑放入问题中。
CustInfo.find\u by\u id(cust\u id)
相当于
CustInfo.find(:first,:conditions=>[“id=?”,cust\u id])
…此处搜索的是
id
列,而不是
cust\u id
列。您说一个客户有多个记录。您能解释一下您的模型和数据库模式吗?您这样做的原因是什么?我以前确实试过。我得到了一个错误:NoMethodError(未定义的方法
eq',用于nil:NilClass):app/controllers/track\u controller.rb:163:in
edit'。我认为这两种方法都应该有效,但我还没有弄清楚为什么会出现这个错误。
find(:all)
将返回一个数组
find(id)
将返回与该id匹配的对象,或
nil
。您必须发布
track\u controller.rb
的内容,以便更深入地了解如何处理下一组错误。此行不再有错误。实际上,
find(id)
不会返回
nil
,如果顾名思义,没有找到记录,它将返回
RecordNotFound
错误。如果希望它返回
nil
而不是
RecordNotFound
,则需要执行
findby\u id(id)
。我明白了。这是有道理的。然而,在这种情况下,它不应该返回nil。我看到了日志,当我使用find(:all,:condition=>cust\u id=cust\u id)时,实际上返回了一些项目。我将把我的控制器逻辑放入问题中。
CustInfo.find\u by\u id(cust\u id)
相当于
CustInfo.find(:first,:conditions=>[“id=?”,cust\u id])
…此处搜索的是
id
列,而不是
cust\u id
列。您说一个客户有多个记录。您能解释一下您的模型和数据库模式吗?
ActionView::Template::Error (undefined method `cust_info_cust_info_path' for #<#<Class:0x7fb0857ce7b8>:0x7fb0857ca780>):
    1: <h1>Editing cust</h1>
    2: 
    3: <%= form_for(@cust_info) do |cust| %>
    4:  Customer: <%= cust.text_field :cust_schema %>
    5:  <%= cust.submit "Save" %>
    6: <% end%>
  app/views/track/edit.html.erb:3:in `_app_views_track_edit_html_erb___102324197_70198065248580_0'
class TrackController < ApplicationController

def display
end

def information
end


def customerinfo
    @cust_info = CustInfo.find(:all, :order=>"cust_id")
    @cust_info.each do |ci|
                    if ci.upload_freq == 'W'
                            ci.upload_freq = 'Weekly'
                    elsif ci.upload_freq == 'M'
                            ci.upload_freq = 'Monthly'
                    end

    end

end


def edit
    cust_id = params[:cust_id]
    @cust_info = CustInfo.find(:all, :conditions => ["cust_id = ?", cust_id])

end