【问题标题】:Routing issue. Url becomes parameter路由问题。 Url 成为参数
【发布时间】:2012-01-02 05:41:13
【问题描述】:

我有一个路径为/user_management/edit_official/:id的网址

它对应的来自rake routes的输出是

user_management_update_official POST   /user_management/edit_official/:id(.:format)           {:controller=>"user_management/employees", :action=>"update_official"}

当我尝试通过表单访问url时,url没有到达,因为url/user_management/edit_official/:id变成了参数。

以下是日志文件条目?

在 127.0.0.1 开始 POST "/user_management/edit_official/31" 2012-01-02 11:05:21 +0530 由 ErrorsController#index 处理 HTML

参数:{"utf8"=>"✓", "authenticity_token"=>"DED4E/9w/GDUQdjZ27mrUWrYBgipgHnNvS8mOjdaNXU=", "员工"=>{"empl_id"=>"", "confirmation_date"=>"", "designation_id"=>"", "rep_head1_id"=>"", "payment_mode"=>"", "pf_number"=>"", "bank_name"=>"", "pt_applicable"=>"false", "reg_date"=>"", "employee_type_id"=>"", "joining_date"=>"", "rep_head2_id"=>"", "pf_applicable"=>"假", "bank_account_number"=>"", "empl_email_id"=>"false", "last_working_date"=>""}, "designation_level"=>"L-5b", "user"=>{"username"=>"dsaf.adsfas", "password"=>"[FILTERED]"}, "commit"=>"下一步", "a"=>"user_management/edit_official/31"}

这有什么原因吗。谢谢。

编辑:包括表格

<% url = user_management_update_official_path(@employee) %>
    <%= form_for(@employee, :url => url, :html => { :enctype => 'multipart/form-data'} ) do |f| %>
      <div id="employee_details" class="employee_form_steps">
        <%= render :partial => 'user_management/employees/official_information', 
          :locals => { :f => f} %>
        </div>
        <div class="btn_row">
          <%= content_tag(:button, '< Back', :id => 'official_information_back', :class => 'grey') %>
          <%= f.submit 'Next', :class => 'green', :style => 'margin:0px;padding:4px;width:50px;' %>
          <%= content_tag(:button, 'Cancel', :class => 'cancel grey') %>
        </div>

      <% end %>

【问题讨论】:

  • 您在 rails 日志中得到的实际错误是什么?
  • @AndrewF,除了我复制的问题之外没有其他错误,

标签: ruby-on-rails ruby-on-rails-3


【解决方案1】:

错误一定在你的routes.rb

此文件中的规则是:先匹配,先送达。

试着把"errors#index"对应的那一行放到描述/user_management/edit_official/:id的那一行下面

【讨论】:

    【解决方案2】:

    实际的问题是用于表单的http 方法。 form_for 使用了put 方法,而在路由中我指定了POST。将POST 更改为PUT,一切正常。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-26
      • 1970-01-01
      • 1970-01-01
      • 2016-04-16
      • 2011-03-09
      相关资源
      最近更新 更多