English 中文(简体)
Railways Routing - :action = 新的回归错误“无航道匹配{:action=>show”。
原标题:Rails Routing - :action => new returns error "No route matches {:action=>"show"... in the same controller

我正在起草一个称为“外部数据库”的模式。

示范档案在分类申报之外没有编码。 我增加了索引、新显示和_form.html.erb的页面。

config/routes.rb 载有“<代码>资源:外部——数据库。 该模式目前没有任何专用资源。 在该申请中还宣布了其他模式,尽管目前没有任何一种模式与这一模式互动,它们都经过测试,在宣布<代码>资源之前已经运作和关闭:外部数据库<>/代码>。

在索引中,我有以下链接:new_external_database_path,如果我正确的话,这种链接就象{:action =>“new”,: Controller =>“external_database”}

这应当从理论上上载数据应用程序/外部数据基/新数据库,使<代码>_form.html.erb。 <代码>第1行>_form :<%=格式_for(@externaldatabase) do OH/code%><>

职称中说明的问题是在使用与新链接时发生的。 尿应用/外部数据库/新系统有以下错误:

<编码> 无航道匹配{:action=>“show”: Controller=>“external_databases”

When I created a data member using rails console, it was displayed properly by index and show. The same _form file is used by the edit method, and successfully edits the console-created data member. Destroy also functions.

...... 因此,为什么没有承认新方法?

My controller code for this model:

    class ExternalDatabasesController < ApplicationController

     def index 
      @external_databases = ExternalDatabase.all

      respond_to do |format|  
       format.html # 指数.html.erb
       format.json { render :json => @external_databases }
      end
     end

     # POST /external_databases
     # POST /external_databases.json

     def new 
      @external_database = ExternalDatabase.new

      respond_to do |format|
       format.html # New.html.erb
       format.json { render :json => @external_database }
      end
     end

     def show
      @external_database = ExternalDatabase.find(params[:id])

      respond_to do |format| 
       format.html # 显示.html.erb
       format.json {render :json => @external_database }
      end
     end

     def create
      @external_database = ExternalDatabase.new(params[:external_database])

      respond_to do |format|
       if @external_database.save
        format.html {redirect_to @external_database, :notice => "New External Database         Profile was created successfully!"}
        format.json {render :json => @external_database, :status => :created, :location => @external_database}
       else
        format.html {render :action => "new"}
        format.json { render :json => @external_database.errors, :status =>         :unprocessable_entity }
       end
      end
     end


     #GET /external_databases/1/edit
     def edit
      @external_database = ExternalDatabase.find(params[:id])
     end

     # PUT /external_databases/1
     # PUT /external_databases/1.json
     def update 
      @external_database = ExternalDatabase.find(params[:id])

      respond_to do |format|
       if @external_database.update_attributes(params[:external_database])
        format.html {redirect_to @external_database, :notice => "External Database         Profile was updated successfully!" }
        format.json {head :ok}
       else 
        format.html { redner :action => "edit" }
        format.json {render :json => @external_database.errors, :status =>         :unprocessable_entity }
       end
      end
     end


     # DELETE /external_databases/1
     # DELETE /external_databases/1.json
     def destroy
      @external_database = ExternalDatabase.find(params[:id])
      @external_database.destroy

      respond_to do |format| 
       format.html { redirect_to external_databases_rul }
       format.json { head :ok }
      end
     end

    end

更新:添加路线.rb和《意见》

My routes.rb file:

    App::Application.routes.draw do

      resources :type_as do 
         resources :type_bs
         end

      resources :type_bs do 
        resources :type_as
        resources :type_cs
        end

      resources :type_cs do
       resources :type_bs
       end

      resources :external_databases

      root :to => "home#index"

    end

View:

外部数据库——格式

    <%= form_for(@external_database) do |f| %>

     <div class="field">
      <%= f.label :name %><br/>
      <%= f.text_field :name %><br/>
     </div>
     <div class="field">
      <%= f.label :description %><br/>
      <%= f.text_field :description %><br/>
     </div>
     <div class="field">
      <%= f.label :url %><br/>
      <%= f.text_field :url %><br/>
     </div>
     <div class="actions">
       <%= f.submit %>
     </div>
    <% end %>

指数.html.erb

    <p id="notice"><%= notice %></p>
    <h1>External Databases</h1>

    <table border="1">
     <tr>
      <th>Database Name</th>
     </tr>
     <% @external_databases.each do |exdb| %>
      <tr>
       <td><%= exdb.name %></td>
       <td><%= truncate(exdb.description) %></td>
       <td><%= link_to  Show , exdb %></td>
       <!-- link_to.... :target => "_blank" will open the url in a new window -->
       <td><%= link_to  Visit , exdb.url, :target => "_blank" %></td>  
       <td><%= link_to  Edit , edit_external_database_path(exdb)%></td>
       <td><%= link_to  Destroy , exdb, :confirm =>  Are you sure? , :method => :delete %></td>
      </tr>
     <% end %>
    </table>

    <br/>
    <%= link_to  New External Database Profile , { :action => "new", :controller => "external_databases" }%> | 
    <%= link_to  Home , root_path %>

New.html.erb

    <h1>Creating a new External Database Profile</h1>

    <%= render  form  %>

    <%= link_to  Back , external_database_path %>

显示.html.erb

    <p id="notice"><%= notice %></p>

    <table cellspacing="3" cellpadding="5" border="1">
     <tr> 
      <th><b>External Database Name</b></th>
      <th><b>Database ID</b></th>
     </tr>
     <tr>
      <td><%= @external_database.name %></td>
      <td><%= @external_database.id %></td>
     </tr>
     <tr colspan="2">
      <th><b>URL</b></th>
     </tr>
     <tr colspan="2">
      <td><%= @external_database.url %></td>
      <td><%= link_to  Visit External Database , @external_database.url %></td>
     </tr>
    </table>



    <p>
     <h3>Description</h3>
     <!% @external_database.description.split.scan(/.{,60}/).each do |line| %>
      <!%= line %><br/>
     <!% end %>
    </p>

    <br /><br /><br />
    <%= link_to  Back to External Database Index , external_databases_path %> |
    <%= link_to  Edit , edit_external_database_path(@external_database) %> | 
    <%= link_to  Destroy , :confirm =>  Are you sure? , :method => :delete %>
最佳回答

你在你的新链接中打字。 应当:

external_databases_path

你可以把它与你自己的背后的联系相比较。 页: 1

固定:新的.html.erb

<h1>Creating a new External Database Profile</h1>

<%= render  form  %>

<%= link_to  Back , external_databases_path %>
问题回答

我有一个类似问题。 随便执行指示。 在我表格“提交守则”的基础上,我建立了新的和删除的纽州。 引证我制造的新错误,是因为有神论删除了纽顿。 不管怎么说,我至少可以评论说,要让新的纽子发挥作用,然后把重点放在把删除的纽扣上。

  = f.submit "Submit", class: "btn btn-large btn-primary"
  = link_to  Create New , new_matrix_header_path, class:  btn btn-primary 
  -#= link_to  Delete , matrix_header_path(@matrix_header), method: :delete, data: { confirm:  Are you sure? }, class:  btn btn-danger 

I looked through the stack and found it beginning the error around line 13 of my view which was the line with my delete button.

Started GET "/matrix_headers/new" for 127.0.0.1 at 2014-10-28 21:08:48 +1000
Processing by MatrixHeadersController#new as HTML
  User Load (0.2ms)  SELECT  `users`.* FROM `users`  WHERE `users`.`id` = 1  ORDER BY `users`.`id` ASC LIMIT 1
  Rendered shared/_error_messages.html.erb (0.4ms)
  Rendered matrix_headers/_form.html.haml (21.0ms)
  Rendered matrix_headers/new.html.haml within layouts/application (22.6ms)
Completed 500 Internal Server Error in 36ms

ActionController::UrlGenerationError - No route matches {:action=>"show", :controller=>"matrix_headers", :format=>nil, :id=>#<MatrixHeader id: nil>} missing required keys: [:id]:
  actionpack (4.1.1) lib/action_dispatch/journey/formatter.rb:39:in `generate 
  actionpack (4.1.1) lib/action_dispatch/routing/route_set.rb:597:in `generate 
  actionpack (4.1.1) lib/action_dispatch/routing/route_set.rb:627:in `generate 
  actionpack (4.1.1) lib/action_dispatch/routing/route_set.rb:663:in `url_for 
  actionpack (4.1.1) lib/action_dispatch/routing/url_for.rb:155:in `url_for 
  actionview (4.1.1) lib/action_view/routing_url_for.rb:83:in `url_for 
  actionpack (4.1.1) lib/action_dispatch/routing/route_set.rb:228:in `call 
  actionpack (4.1.1) lib/action_dispatch/routing/route_set.rb:179:in `call 
  actionpack (4.1.1) lib/action_dispatch/routing/route_set.rb:268:in `block (2 levels) in define_url_helper 
   () media/jay/DATA/rails_projects/my_app/app/views/matrix_headers/_form.html.haml:13:in `block in _app_views_matrix_headers__form_html_haml__2669648707298145379_8667520 

By commenting out the delete button it now routes through to new correctly without going to the No route matches {:action=>"show" error.





相关问题
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: ...

热门标签