Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 联系人中的NoMethodError#索引-联系人中的NoMethodError#索引_Ruby On Rails_Ruby - Fatal编程技术网

Ruby on rails 联系人中的NoMethodError#索引-联系人中的NoMethodError#索引

Ruby on rails 联系人中的NoMethodError#索引-联系人中的NoMethodError#索引,ruby-on-rails,ruby,Ruby On Rails,Ruby,尝试从联系人模型的索引向我的代表模型添加编辑链接时出错。我上个星期让它工作了,但是我现在已经对我的数据库进行了更改,并且我有一个可以工作的联系人的编辑链接,但是当我添加路径edit_rep_path(rep)时,我得到了错误。我的所有代码都遵循完整的跟踪: 完整跟踪: activemodel (3.2.1) lib/active_model/conversion.rb:52:in `to_param' actionpack (3.2.1) lib/action_dispatch/routing/

尝试从联系人模型的索引向我的代表模型添加编辑链接时出错。我上个星期让它工作了,但是我现在已经对我的数据库进行了更改,并且我有一个可以工作的联系人的编辑链接,但是当我添加路径edit_rep_path(rep)时,我得到了错误。我的所有代码都遵循完整的跟踪:

完整跟踪:

activemodel (3.2.1) lib/active_model/conversion.rb:52:in `to_param'
actionpack (3.2.1) lib/action_dispatch/routing/route_set.rb:417:in `block in <class:Generator>'
journey (1.0.4) lib/journey/formatter.rb:31:in `call'
journey (1.0.4) lib/journey/formatter.rb:31:in `block (2 levels) in generate'
journey (1.0.4) lib/journey/formatter.rb:30:in `each'
journey (1.0.4) lib/journey/formatter.rb:30:in `block in generate'
journey (1.0.4) lib/journey/formatter.rb:60:in `match_route'
journey (1.0.4) lib/journey/formatter.rb:16:in `generate'
actionpack (3.2.1) lib/action_dispatch/routing/route_set.rb:510:in `generate'
actionpack (3.2.1) lib/action_dispatch/routing/route_set.rb:551:in `generate'
actionpack (3.2.1) lib/action_dispatch/routing/route_set.rb:576:in `url_for'
actionpack (3.2.1) lib/action_dispatch/routing/url_for.rb:148:in `url_for'
actionpack (3.2.1) lib/action_view/helpers/url_helper.rb:107:in `url_for'
actionpack (3.2.1) lib/action_dispatch/routing/route_set.rb:202:in `edit_rep_path'
app/views/contacts/index.html.erb:88:in `block in _app_views_contacts_index_html_erb___595989602_34757832'
app/views/contacts/index.html.erb:79:in `each'
app/views/contacts/index.html.erb:79:in `_app_views_contacts_index_html_erb___595989602_34757832'
actionpack (3.2.1) lib/action_view/template.rb:143:in `block in render'
activesupport (3.2.1) lib/active_support/notifications.rb:125:in `instrument'
actionpack (3.2.1) lib/action_view/template.rb:141:in `render'
actionpack (3.2.1) lib/action_view/renderer/template_renderer.rb:41:in `block (2 levels) in render_template'
actionpack (3.2.1) lib/action_view/renderer/abstract_renderer.rb:38:in `block in instrument'
activesupport (3.2.1) lib/active_support/notifications.rb:123:in `block in instrument'
activesupport (3.2.1) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (3.2.1) lib/active_support/notifications.rb:123:in `instrument'
actionpack (3.2.1) lib/action_view/renderer/abstract_renderer.rb:38:in `instrument'
actionpack (3.2.1) lib/action_view/renderer/template_renderer.rb:40:in `block in render_template'
actionpack (3.2.1) lib/action_view/renderer/template_renderer.rb:48:in `render_with_layout'
actionpack (3.2.1) lib/action_view/renderer/template_renderer.rb:39:in `render_template'
actionpack (3.2.1) lib/action_view/renderer/template_renderer.rb:12:in `render'
actionpack (3.2.1) lib/action_view/renderer/renderer.rb:36:in `render_template'
actionpack (3.2.1) lib/action_view/renderer/renderer.rb:17:in `render'
actionpack (3.2.1) lib/abstract_controller/rendering.rb:109:in `_render_template'
actionpack (3.2.1) lib/action_controller/metal/streaming.rb:225:in `_render_template'
actionpack (3.2.1) lib/abstract_controller/rendering.rb:103:in `render_to_body'
actionpack (3.2.1) lib/action_controller/metal/renderers.rb:28:in `render_to_body'
actionpack (3.2.1) lib/action_controller/metal/compatibility.rb:50:in `render_to_body'
actionpack (3.2.1) lib/abstract_controller/rendering.rb:88:in `render'
actionpack (3.2.1) lib/action_controller/metal/rendering.rb:16:in `render'
actionpack (3.2.1) lib/action_controller/metal/instrumentation.rb:40:in `block (2 levels) in render'
activesupport (3.2.1) lib/active_support/core_ext/benchmark.rb:5:in `block in ms'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/benchmark.rb:295:in `realtime'
activesupport (3.2.1) lib/active_support/core_ext/benchmark.rb:5:in `ms'
actionpack (3.2.1) lib/action_controller/metal/instrumentation.rb:40:in `block in render'
actionpack (3.2.1) lib/action_controller/metal/instrumentation.rb:83:in `cleanup_view_runtime'
activerecord (3.2.1) lib/active_record/railties/controller_runtime.rb:24:in `cleanup_view_runtime'
actionpack (3.2.1) lib/action_controller/metal/instrumentation.rb:39:in `render'
actionpack (3.2.1) lib/action_controller/metal/implicit_render.rb:10:in `default_render'
actionpack (3.2.1) lib/action_controller/metal/implicit_render.rb:5:in `send_action'
actionpack (3.2.1) lib/abstract_controller/base.rb:167:in `process_action'
actionpack (3.2.1) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (3.2.1) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (3.2.1) lib/active_support/callbacks.rb:414:in `_run__206336291__process_action__115771758__callbacks'
activesupport (3.2.1) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.1) lib/active_support/callbacks.rb:385:in `_run_process_action_callbacks'
activesupport (3.2.1) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.1) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (3.2.1) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (3.2.1) lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
activesupport (3.2.1) lib/active_support/notifications.rb:123:in `block in instrument'
activesupport (3.2.1) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (3.2.1) lib/active_support/notifications.rb:123:in `instrument'
actionpack (3.2.1) lib/action_controller/metal/instrumentation.rb:29:in `process_action'
actionpack (3.2.1) lib/action_controller/metal/params_wrapper.rb:205:in `process_action'
activerecord (3.2.1) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (3.2.1) lib/abstract_controller/base.rb:121:in `process'
actionpack (3.2.1) lib/abstract_controller/rendering.rb:45:in `process'
actionpack (3.2.1) lib/action_controller/metal.rb:203:in `dispatch'
actionpack (3.2.1) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
actionpack (3.2.1) lib/action_controller/metal.rb:246:in `block in action'
actionpack (3.2.1) lib/action_dispatch/routing/route_set.rb:66:in `call'
actionpack (3.2.1) lib/action_dispatch/routing/route_set.rb:66:in `dispatch'
actionpack (3.2.1) lib/action_dispatch/routing/route_set.rb:30:in `call'
journey (1.0.4) lib/journey/router.rb:68:in `block in call'
journey (1.0.4) lib/journey/router.rb:56:in `each'
journey (1.0.4) lib/journey/router.rb:56:in `call'
actionpack (3.2.1) lib/action_dispatch/routing/route_set.rb:589:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
rack (1.4.5) lib/rack/etag.rb:23:in `call'
rack (1.4.5) lib/rack/conditionalget.rb:25:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/head.rb:14:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/flash.rb:242:in `call'
rack (1.4.5) lib/rack/session/abstract/id.rb:210:in `context'
rack (1.4.5) lib/rack/session/abstract/id.rb:205:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/cookies.rb:338:in `call'
activerecord (3.2.1) lib/active_record/query_cache.rb:64:in `call'
activerecord (3.2.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:443:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
activesupport (3.2.1) lib/active_support/callbacks.rb:405:in `_run__120318686__call__42201320__callbacks'
activesupport (3.2.1) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.1) lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
activesupport (3.2.1) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.1) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/reloader.rb:65:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
railties (3.2.1) lib/rails/rack/logger.rb:26:in `call_app'
railties (3.2.1) lib/rails/rack/logger.rb:16:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/request_id.rb:22:in `call'
rack (1.4.5) lib/rack/methodoverride.rb:21:in `call'
rack (1.4.5) lib/rack/runtime.rb:17:in `call'
activesupport (3.2.1) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.4.5) lib/rack/lock.rb:15:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/static.rb:53:in `call'
railties (3.2.1) lib/rails/engine.rb:479:in `call'
railties (3.2.1) lib/rails/application.rb:220:in `call'
rack (1.4.5) lib/rack/content_length.rb:14:in `call'
railties (3.2.1) lib/rails/rack/log_tailer.rb:14:in `call'
rack (1.4.5) lib/rack/handler/webrick.rb:59:in `service'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run'
C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'
观点: 联络 indes.html.erb

<a href="http://www.newsouthsupply.com/index.htm">
<img src="http://www.newsouthcatalog.com/uploads/57/Logo/New-South-Construction-Supply-Logo.png" alt="Home Page" align="left" title="New South Supply Home" width="150" height="150"/>
</a>
<a href="http://www.newsouthcatalog.com/">
<img src="http://www.newsouthcatalog.com/uploads/57/Logo/New-South-Construction-Supply-Logo.png" alt="Online Catalog" title="New South Supply Online Catalog" align="right" width="130" height="150"/>
</a>
<center>
<h1>New South Construction Supply's Contact Information</h1>
<h2>Please take a few minutes out of your busy day to help us keep our records up to date.</h2>
<h2>Enter company id</h2>

<!-- Text Box and Search Button -->
<%= form_tag contacts_path, :method => 'get' do %>
  <p>
    <%= text_field_tag :search, params[:search] %>
    <%= submit_tag "Search", :name => nil %>

  </p>
<% end %>
<font color="000000">

<!-- Table of Company Information -->    
<h2>Company Information</h2>
<font color = "BDBEBF">
<div style="margin:0 auto;background-color:#000000;width:100%;">
<table width="100%" border ="1">
  <tr>
    <th><font color="5780AE">Reference</th>
    <th><font color="5780AE">Company Id</th>
    <th><font color="5780AE">Name</th>
    <th><font color="5780AE">Mail address</th>
    <th><font color="5780AE">Physical address</th>
    <th><font color="5780AE">Phone</th>
    <th><font color="5780AE">Fax</th>
    <th><font color="5780AE">Email</th>
    <th><font color="5780AE">Delete Flag</th>
    <th></th>
    <!--<th></th>-->
  </tr>
<!-- Populate Table -->


<% @contacts.each do |contact| %>
  <tr>
    <td><center><%= contact.Ref %></td>
    <td><center><%= contact.Company_Id %></td>
    <td><center><%= contact.Name %></td>
    <td><center><%= contact.Mail_Address %></td>
    <td><center><%= contact.Physical_Address %></td>
    <td><center><%= contact.Phone %></td>
    <td><center><%= contact.Fax %></td>
    <td><center><%= contact.Email %></td>
    <td><center><%= contact.Delete_Flag %></td>
    <td><center><%= link_to 'Edit', edit_contact_path(contact), {:style => 'color:#E86A10', :class => "css_class"} %></td>
    <!--<td><%= link_to 'Delete', contact, confirm: 'Are you sure?', method: :delete, :style => 'color:#E86A10', :class => "css_class" %></td> -->
  </tr>
<%end%>
</table>
</div>
<font color="000000">
<h1>  </h1>

<!-- Table of Company's Contact Information -->
<h2> Contact Information </h2>
<font color="BDBEBF">
<div style="margin:0 auto;background-color:#000000;width:100%;">
<table border="1" width = "100%">
  <tr>
    <th><font color="5780AE">First</th>
    <th><font color="5780AE">Last</th>
    <th><font color="5780AE">Phone</th>
    <th><font color="5780AE">P ext</th>
    <th><font color="5780AE">Fax</th>
    <th><font color="5780AE">Email</th>
    <th><font color="5780AE">Delete Flag</th>
    <th></th>
  </tr>
<!-- Populate Table -->
<% @reps.each do |rep|%>
  <tr>
    <td><center><%= rep.First %></td>
    <td><center><%= rep.Last %></td>
    <td><center><%= rep.Phone %></td>
    <td><center><%= rep.P_ext %></td>
    <td><center><%= rep.Fax %></td>
    <td><center><%= rep.Email %></td>
    <td><center><%= rep.Delete_Flag %></td>
    <%= link_to 'Edit Rep', edit_rep_path(rep), {:style => 'color:#000000', :class => "css_class"} %>
  </tr>
<%end%>
</table>
</div>
<%= link_to 'Add New Rep', new_rep_path, {:style => 'color:#000000', :class => "css_class"} %>
</center>

<br />

新南建设供应部的联系信息
请在您忙碌的一天中抽出几分钟时间,帮助我们更新记录。
输入公司id
'获取'执行%>

零%>

公司信息 参考文献 公司Id 名称 邮寄地址 物理地址 电话 传真 电子邮件 删除标志 'color:#E86A10',:class=>css_class}%> 联系方式 弗斯特 最后 电话 外文 传真 电子邮件 删除标志 'color:#000000',:class=>css\u class}%> 'color:#000000',:class=>css\u class}%>
edit.html.erb

<center>
<h1>Editing contact</h1>

<%= render 'form' %>

<%= link_to 'Show', @contact, {:style => 'color:#000000', :class => "css_class"} %> 
<!--<%= link_to 'Back', contacts_path %>
<%= form_tag contacts_path, :method => 'get' do %>
  <p>
    <%= text_field_tag :search, params[:search] %>
    <%= submit_tag "Search", :name => nil %>

  </p>
<% end %>-->
</center>
<center>
<h1>Editing rep</h1>

<%= render 'form' %>

<%= link_to 'Show', @rep, {:style => 'color:#000000', :class => "css_class"} %> 
<!--<%= link_to 'Back', contacts_path %>
<%= form_tag contacts_path, :method => 'get' do %>
  <p>
    <%= text_field_tag :search, params[:search] %>
    <%= submit_tag "Search", :name => nil %>

  </p>
<% end %>-->
</center>

编辑联系人
'color:#000000',:class=>css\u class}%>
代表 edit.html.erb

<center>
<h1>Editing contact</h1>

<%= render 'form' %>

<%= link_to 'Show', @contact, {:style => 'color:#000000', :class => "css_class"} %> 
<!--<%= link_to 'Back', contacts_path %>
<%= form_tag contacts_path, :method => 'get' do %>
  <p>
    <%= text_field_tag :search, params[:search] %>
    <%= submit_tag "Search", :name => nil %>

  </p>
<% end %>-->
</center>
<center>
<h1>Editing rep</h1>

<%= render 'form' %>

<%= link_to 'Show', @rep, {:style => 'color:#000000', :class => "css_class"} %> 
<!--<%= link_to 'Back', contacts_path %>
<%= form_tag contacts_path, :method => 'get' do %>
  <p>
    <%= text_field_tag :search, params[:search] %>
    <%= submit_tag "Search", :name => nil %>

  </p>
<% end %>-->
</center>

编辑代表
'color:#000000',:class=>css\u class}%>

添加您的
routes.rb
和您得到的完整错误您可以运行
rake routes
来显示从
routes.rb
生成的各种路由,并验证
edit_rep_path
是否存在,它是否接受参数以及它指向的控制器/操作。
class Rep < ActiveRecord::Base
    attr_accessible :Ref, :Company_Id, :Company, :First, :Last, :Phone, :P_ext, :Fax, :F_ext, :Email, :Delete_Flag
    belongs_to :contacts
    def self.search(search)
        if search
            find(:all, :conditions => ['Ref LIKE ?', "#{search}"])
        else
            find(:all, :conditions => ['Ref LIKE ?', nil])
        end
    end
end
ContactsInfo::Application.routes.draw do
  #get "search/create"

  resources :contacts

  resources :reps

  get "home/index"

   root :to => 'home#index'

end
<a href="http://www.newsouthsupply.com/index.htm">
<img src="http://www.newsouthcatalog.com/uploads/57/Logo/New-South-Construction-Supply-Logo.png" alt="Home Page" align="left" title="New South Supply Home" width="150" height="150"/>
</a>
<a href="http://www.newsouthcatalog.com/">
<img src="http://www.newsouthcatalog.com/uploads/57/Logo/New-South-Construction-Supply-Logo.png" alt="Online Catalog" title="New South Supply Online Catalog" align="right" width="130" height="150"/>
</a>
<center>
<h1>New South Construction Supply's Contact Information</h1>
<h2>Please take a few minutes out of your busy day to help us keep our records up to date.</h2>
<h2>Enter company id</h2>

<!-- Text Box and Search Button -->
<%= form_tag contacts_path, :method => 'get' do %>
  <p>
    <%= text_field_tag :search, params[:search] %>
    <%= submit_tag "Search", :name => nil %>

  </p>
<% end %>
<font color="000000">

<!-- Table of Company Information -->    
<h2>Company Information</h2>
<font color = "BDBEBF">
<div style="margin:0 auto;background-color:#000000;width:100%;">
<table width="100%" border ="1">
  <tr>
    <th><font color="5780AE">Reference</th>
    <th><font color="5780AE">Company Id</th>
    <th><font color="5780AE">Name</th>
    <th><font color="5780AE">Mail address</th>
    <th><font color="5780AE">Physical address</th>
    <th><font color="5780AE">Phone</th>
    <th><font color="5780AE">Fax</th>
    <th><font color="5780AE">Email</th>
    <th><font color="5780AE">Delete Flag</th>
    <th></th>
    <!--<th></th>-->
  </tr>
<!-- Populate Table -->


<% @contacts.each do |contact| %>
  <tr>
    <td><center><%= contact.Ref %></td>
    <td><center><%= contact.Company_Id %></td>
    <td><center><%= contact.Name %></td>
    <td><center><%= contact.Mail_Address %></td>
    <td><center><%= contact.Physical_Address %></td>
    <td><center><%= contact.Phone %></td>
    <td><center><%= contact.Fax %></td>
    <td><center><%= contact.Email %></td>
    <td><center><%= contact.Delete_Flag %></td>
    <td><center><%= link_to 'Edit', edit_contact_path(contact), {:style => 'color:#E86A10', :class => "css_class"} %></td>
    <!--<td><%= link_to 'Delete', contact, confirm: 'Are you sure?', method: :delete, :style => 'color:#E86A10', :class => "css_class" %></td> -->
  </tr>
<%end%>
</table>
</div>
<font color="000000">
<h1>  </h1>

<!-- Table of Company's Contact Information -->
<h2> Contact Information </h2>
<font color="BDBEBF">
<div style="margin:0 auto;background-color:#000000;width:100%;">
<table border="1" width = "100%">
  <tr>
    <th><font color="5780AE">First</th>
    <th><font color="5780AE">Last</th>
    <th><font color="5780AE">Phone</th>
    <th><font color="5780AE">P ext</th>
    <th><font color="5780AE">Fax</th>
    <th><font color="5780AE">Email</th>
    <th><font color="5780AE">Delete Flag</th>
    <th></th>
  </tr>
<!-- Populate Table -->
<% @reps.each do |rep|%>
  <tr>
    <td><center><%= rep.First %></td>
    <td><center><%= rep.Last %></td>
    <td><center><%= rep.Phone %></td>
    <td><center><%= rep.P_ext %></td>
    <td><center><%= rep.Fax %></td>
    <td><center><%= rep.Email %></td>
    <td><center><%= rep.Delete_Flag %></td>
    <%= link_to 'Edit Rep', edit_rep_path(rep), {:style => 'color:#000000', :class => "css_class"} %>
  </tr>
<%end%>
</table>
</div>
<%= link_to 'Add New Rep', new_rep_path, {:style => 'color:#000000', :class => "css_class"} %>
</center>

<br />
<center>
<h1>Editing contact</h1>

<%= render 'form' %>

<%= link_to 'Show', @contact, {:style => 'color:#000000', :class => "css_class"} %> 
<!--<%= link_to 'Back', contacts_path %>
<%= form_tag contacts_path, :method => 'get' do %>
  <p>
    <%= text_field_tag :search, params[:search] %>
    <%= submit_tag "Search", :name => nil %>

  </p>
<% end %>-->
</center>
<center>
<h1>Editing rep</h1>

<%= render 'form' %>

<%= link_to 'Show', @rep, {:style => 'color:#000000', :class => "css_class"} %> 
<!--<%= link_to 'Back', contacts_path %>
<%= form_tag contacts_path, :method => 'get' do %>
  <p>
    <%= text_field_tag :search, params[:search] %>
    <%= submit_tag "Search", :name => nil %>

  </p>
<% end %>-->
</center>