具有奇异资源错误的自定义路由

时间:2014-06-06 09:47:34

标签: ruby-on-rails routing

我的路线看起来像这样

的routes.rb

 get    '/:pimp_id/mepagers(.:format)',     :to => 'mepagers#index',    :as => 'mepagers'
 get    '/:pimp_id/mepager/new(.:format)',  :to => 'mepagers#new',      :as => 'new_mepager'
 get    '/:pimp_id/mepager/edit(.:format)', :to => 'mepagers#edit',     :as => 'edit_mepager'
 get    '/:pimp_id/mepager(.:format)',      :to => 'mepagers#show',     :as => 'mepager'
 post   '/:pimp_id/mepager(.:format)',      :to => 'mepagers#create',   :as => 'create_mepager'
 put    '/:pimp_id/mepager(.:format)',      :to => 'mepagers#update'
 patch  '/:pimp_id/mepager(.:format)',      :to => 'mepagers#update'
 delete '/:pimp_id/mepager(.:format)',      :to => 'mepagers#destroy'

我试图从

中获取表格
HTTP Verb Path Controller#Action Used for 
GET /geocoder/new geocoders#new return an HTML form for creating the geocoder 
POST /geocoder geocoders#create create the new geocoder 
GET /geocoder geocoders#show display the one and only geocoder resource 
GET /geocoder/edit geocoders#edit return an HTML form for editing the geocoder 
PATCH/PUT /geocoder geocoders#update update the one and only geocoder resource 
DELETE /geocoder geocoders#destroy delete the geocoder resource

(来源http://guides.rubyonrails.org/routing.html

但是当我点击/ 1 / mepager / new上的提交按钮时,我收到以下错误:

Routing Error
No route matches [POST] "/1/mepager/new"

我甚至试图将后期行动路线更改为/ 1 / mepager / new,但这根本没有帮助,因为他无法找到mepager的参数。 Coudlnt在谷歌上发现任何类似的东西,所以我希望有人可以帮助这个路由让我生病!

new.html.erb

<%= render 'form' %>

<%= link_to 'Back', pimps_path %>

_form.html.erb

<%= form_for 'mepager_path' do |f| %>

  <% if @mepager.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(@mepager.errors.count, "error") %> prohibited this mepager from being saved:</h2>

      <ul>
      <% @mepager.errors.full_messages.each do |msg| %>
        <li><%= msg %></li>
      <% end %>
      </ul>
    </div>
  <% end %>


<table style="border:1px solid black; border-spacing:5px"; width="1521" bgcolor="#DFDFDF">

    <colgroup>
        <col width="1050">
        <col width="300">
    </colgroup>

    <tr> <td>   <h1>NEW: ID# Title  </td>   <td> <h1>Programme:  a350</h1></td> </tr>
</table>





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

<table style="border:1px solid black; border-spacing:5px"; width="1500"; height="640">

    <tr>
        <th rowspan="3">
            <table style="border:1px solid black; border-spacing:5px"; width="1150"; height="506">
                <colgroup>
                    <col width="675">
                    <col width="675">
                </colgroup>


                <tr>    <th colspan="2" align="left" height="10">   <u><strong>Change description & pictures:</strong></u>  </th>   </tr>

                <tr>    <th colspan="2" align="left" height="10">   <u><b>Pre:</b></u>                                      </th>   </tr>                   
                <tr>    
                    <td align="left" valign="top">  <div class="field"> <%= f.text_area :pre, :size=>"100x12"%> </div>  </td>   
                    <td>    
                        <div class="actions">     
                            <%= file_field_tag :file %>   
                            <%= submit_tag "Upload image" %> 
                        </div> 
                    </td>       
                </tr>

                <tr>    <th colspan="2" align="left" height="10">   <u><b>Post:</b></u>                                     </th>   </tr>
                <tr>    
                    <td align="left" valign="top">  <div class="field"> <%= f.text_area :post, :size=>"100x12" %>   </div>  </td>   
                    <td>
                        <div class="actions">     
                            <%= file_field_tag :file %>   
                            <%= submit_tag "Upload image" %> 
                        </div> 
                    </td>   
                </tr>




            </table>
        </th>
        <td valign="top">
            <table style="border:1px solid black; border-spacing:5px"; width="350"; height=135>
                <colgroup>
                    <col width="160">
                    <col width="190">
                </colgroup>

                <tr>    <th colspan="2" align="left" height="10">   <u><strong>Expected savings / overspend reduction:</strong></u> </th>                               </tr>       
                <tr>    <td align="left">   h/AC:   </td>   <td align="left">   <div class="field"> <%= f.number_field :save_h, :size=>5 %> </div>  </td>           </tr>
                <tr>    <td align="left">   concessions/AC: </td>   <td align="left">   <div class="field"> <%= f.number_field :save_c, :size=>5 %> </div>  </td>   </tr>
                <tr>    <td align="left">   others: </td>   <td align="left">   <div class="field"> <%= f.text_field :save_other, :size=>30 %>  </div>  </td>           </tr>           
            </table>
        </td>
    </tr>
    <tr>
        <td>
            <table style="border:1px solid black; border-spacing:5px"; width="350"; height=180>
                <colgroup>
                    <col width="160">
                    <col width="190">
                </colgroup>


                <tr>    <th colspan="2" align="left" height="10">   <u><strong>Affected domains / responsibility:</strong></u>  </th>                                       </tr>       
                <tr>    <td align="left">   Design: </td>   <td align="left">   <div class="field"> <%= f.text_field :affect_design, :size=>30 %>   </div>  </td>       </tr>
                <tr>    <td align="left">   Stress: </td>   <td align="left">   <div class="field"> <%= f.text_field :affect_stress, :size=>30 %>   </div>  </td>       </tr>
                <tr>    <td align="left">   Manufacturing:  </td>   <td align="left">   <div class="field"> <%= f.text_field :affect_me, :size=>30 %>   </div>  </td>   </tr>
                <tr>    <td align="left">   Others: </td>   <td align="left">   <div class="field"> <%= f.text_field :affect_other, :size=>30 %>    </div>  </td>       </tr>   
            </table>
        </td>
    </tr>
    <tr>
        <td>
            <table style="border:1px solid black; border-spacing:5px"; width="350"; height=135>
                <colgroup>
                    <col width="160">
                    <col width="190">
                </colgroup>

                <tr>    <th colspan="2" align="left" height="10">   <u><strong>Affected documents:</strong> </u>    </th>   </tr>       
                <tr>    <td align="left">   Drawing number/HTZ: </td>   <td align="left">   <div class="field"> <%= f.text_field :affect_dno, :size=>30 %>  </div>  </td>   </tr>
                <tr>    <td align="left">   Material ID:    </td>   <td align="left">   <div class="field"> <%= f.text_field :affect_mid, :size=>30 %>  </div>  </td>       </tr>
                <tr>    <td align="left">   Others: </td>   <td align="left">   <div class="field"> <%= f.text_field :affect_otherdoc, :size=>30 %> </div>  </td>               </tr>
            </table>            
        </td>
    </tr>
    <tr>
        <td>
            <table style="border:1px solid black; border-spacing:5px"; width="1150"; height=196>
                <tr height="10">    <th align="left">   <u><b>Comments / current status / further notes:</b></u>    </th>   </tr>       
                <tr>    <td align="left" valign="top">  <div class="field">  <%= f.text_area :save_h, :size=>"100x8"%> </div> </td>     </tr>       
            </table>
        </td>
        <td> 
            <table style="border:1px solid black; border-spacing:5px"; width="350"; height=150>
                <colgroup>
                    <col width="160">
                    <col width="190">
                </colgroup>

                <tr>    <th colspan="2" align="left" height="10">   <u><strong>General information:</strong></u>    </th>   </tr>   
                <tr>    <td align="left">   Idea owner: </td>   <td align="left">   <div class="field"> <%= f.text_field :owner, :size=>30 %>   </div>  </td>               </tr>
                <tr>    <td align="left">   Date of submission: </td>   <td align="left">   autofilled  </td>               </tr>
                <tr>    <td align="left">   PPS available:  </td>   <td align="left">   <div class="field"> <%= f.text_field :pps, :size=>30 %> </div>  </td>               </tr>
                <tr>    <td align="left">   Reference (VV/ZTV): </td>   <td align="left">   <div class="field"> <%= f.text_field :reference, :size=>30 %>   </div>  </td>   </tr>
            </table>
        </td>
    </tr>
</table>        



  <div class="actions">
    <%= f.submit "Create One Pager" %>
  </div>

<% end %>

1 个答案:

答案 0 :(得分:0)

请参阅form_for here

上的文档

参考与上述有关的文件; form_for方法需要一些参数:

  1. 记录
  2. 选项
  3. 在您的情况下,我认为您要做的是将'mepager_path'命名路径作为应提交表单的URL。但是,您错过了form_for参数的分隔符,因此Rails认为'mepager_path'record参数的值。

    record参数用于传达有关表单应描述的对象的信息,以便Rails可以推断对象的属性,从而为您创建表单,而开发人员的开销最小。在你的情况下,我认为你可以尝试像

    <%= form_for :mepager, url: mepager_path do |f| %>
    

    我也是一个Rails noob,所以我不能保证我的代码示例是正确的,但我的答案的要点是你的form_for参数不正确。作为Rails的新手,我不断受到不同形式参数的挫败感。对我来说,多种形式使它们难以阅读,我不断地确保我不会误解代码。此外,哈希语法总是让我困惑。

    我的回答来自here。我发现它是一个非常有用的参考站点。

    希望我的回答可以帮到你。