0

尝试从联系人模型的索引向代表模型添加编辑链接时出现错误。上周我让它工作了,但我现在已经对我的数据库进行了更改,并且我有一个有效的联系人的编辑链接,但是当我添加路径时,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'

Db 迁移文件:create_contacts.rb

    class CreateContacts < ActiveRecord::Migration
  def change
    create_table :contacts do |t|
      t.integer :Ref
      t.integer :Company_Id
      t.string :Name
      t.string :Mail_Address
      t.string :Physical_Address
      t.string :Phone
      t.string :Fax
      t.string :Email
      t.string :Delete_Flag

      t.timestamps
    end
  end
end

create_reps.rb

    class CreateReps < ActiveRecord::Migration
  def change
    create_table :reps do |t|
      t.integer :Ref
      t.integer :Company_Id
      t.string :Company
      t.string :First
      t.string :Last
      t.string :Phone
      t.string :P_ext
      t.string :Fax
      t.string :F_ext
      t.string :Email
      t.string :Delete_Flag

      t.timestamps
    end
  end
end

控制器:contacts_controller.rb

class ContactsController < ApplicationController
  # GET /contacts
  # GET /contacts.json
  def index
    @contacts = Contact.search(params[:search])
    @reps = Rep.search(params[:search])
  end

  # GET /contacts/1
  # GET /contacts/1.json
  def show
    @contact = Contact.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.json { render json: @contact }
    end
  end

  # GET /contacts/new
  # GET /contacts/new.json
  def new
    @contact = Contact.new

    respond_to do |format|
      format.html # new.html.erb
      format.json { render json: @contact }
    end
  end

  # GET /contacts/1/edit
  def edit
    @contact = Contact.find(params[:id])
  end

  # POST /contacts
  # POST /contacts.json
  def create
    @contact = Contact.new(params[:contact])

    respond_to do |format|
      if @contact.save
        format.html { redirect_to @contact, notice: 'Contact was successfully created.' }
        format.json { render json: @contact, status: :created, location: @contact }
      else
        format.html { render action: "new" }
        format.json { render json: @contact.errors, status: :unprocessable_entity }
      end
    end
  end

  # PUT /contacts/1
  # PUT /contacts/1.json
  def update
    @contact = Contact.find(params[:id])

    respond_to do |format|
      if @contact.update_attributes(params[:contact])
        format.html { redirect_to @contact, notice: 'Contact was successfully updated.' }
        format.json { head :no_content }
      else
        format.html { render action: "edit" }
        format.json { render json: @contact.errors, status: :unprocessable_entity }
      end
    end
  end

  # DELETE /contacts/1
  # DELETE /contacts/1.json
  def destroy
    @contact = Contact.find(params[:id])
    @contact.destroy

    respond_to do |format|
      format.html { redirect_to contacts_url }
      format.json { head :no_content }
    end
  end

end

reps_controller.rb

class RepsController < ApplicationController
  # GET /reps
  # GET /reps.json
  def index
    @rep = Rep.all

    respond_to do |format|
      format.html # index.html.erb
      format.json { render json: @reps }
    end
  end

  # GET /reps/1
  # GET /reps/1.json
  def show
    @rep = Rep.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.json { render json: @rep }
    end
  end

  # GET /reps/new
  # GET /reps/new.json
  def new
    @rep = Rep.new

    respond_to do |format|
      format.html # new.html.erb
      format.json { render json: @rep }
    end
  end

  # GET /reps/1/edit
  def edit
    @rep = Rep.find(:all, params[:id])

  end

  # POST /reps
  # POST /reps.json
  def create
    @rep = Rep.new(params[:rep])

    respond_to do |format|
      if @rep.save
        format.html { redirect_to @rep, notice: 'Rep was successfully created.' }
        format.json { render json: @rep, status: :created, location: @rep }
      else
        format.html { render action: "new" }
        format.json { render json: @rep.errors, status: :unprocessable_entity }
      end
    end
  end

  # PUT /reps/1
  # PUT /reps/1.json
  def update
    @rep = Rep.find(params[:id])

    respond_to do |format|
      if @rep.update_attributes(params[:rep])
        format.html { redirect_to @rep, notice: 'Rep was successfully updated.' }
        format.json { head :no_content }
      else
        format.html { render action: "edit" }
        format.json { render json: @rep.errors, status: :unprocessable_entity }
      end
    end
  end

  # DELETE /reps/1
  # DELETE /reps/1.json
  def destroy
    @rep = Rep.find(params[:id])
    @rep.destroy

    respond_to do |format|
      format.html { redirect_to contacts_url }
      format.json { head :no_content }
    end
  end
end

型号:contact.rb

class Contact < ActiveRecord::Base
    attr_accessible :Name, :Mail_Address, :Physical_Address, :Phone, :Fax, :Email

    validates :Name, :presence => true
    validates :Mail_Address, :presence => true
    validates :Physical_Address, :presence => true
    validates :Phone, :presence => true,
                        :length => { :minimum => 10}
    validates :Fax, :presence => true,
                        :length => { :minimum => 10}
    validates :Email, :presence => true

    has_many :reps
    def self.search(search)
        if search
            find(:all, :conditions => ['Ref LIKE ?', "#{search}"])
        else
            find(:all, :conditions => ['Ref LIKE ?', nil])
        end
    end
end

代表.rb

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

路线.rb

ContactsInfo::Application.routes.draw do
  #get "search/create"

  resources :contacts

  resources :reps

  get "home/index"

   root :to => 'home#index'

end

意见:联系人 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 />

编辑.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>

代表 edit.html.erb

<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>
4

0 回答 0