link_to编辑页面默认路径?

时间:2011-08-22 15:24:30

标签: ruby-on-rails

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

<td class="edit" id="edit">edit
<%= link_to 'edit', :action => :edit, :cust_id => ci.cust_id %>
</td>

edit.html.erb:

<h1>Editing cust</h1>
<%= form_for(@cust_info) do |cust| %>
    Customer: <%= cust.text_field :cust_schema %>
    <%= cust.submit "Save" %>
<% end%>

在我的控制器中,我有这个:

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

客户信息页面显示正确。当我单击编辑链接时,收到错误消息:

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'

`cust_info_cust_info_path'来自哪里?

编辑:这是控制器中的代码:

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 

端 端

1 个答案:

答案 0 :(得分:0)

更改@cust_info = CustInfo.find(:all, :conditions => ["cust_id = ?", cust_id])

@cust_info = CustInfo.find(cust_id)