Redmine插件开发编辑form_for

时间:2016-08-04 09:18:11

标签: ruby-on-rails-4 redmine form-for editview

我正在开发一个redmine插件, 到目前为止它进展顺利。但是,由于我将插件集成到一个项目中,因此无法使用form_for创建编辑视图。

修改视图:

Formular
<div class="box tabular">
<div class="splitcontent">
<div class="splitcontentleft">
<%= form_for (@customer) do |f| %>
  <div class="splitcontent">
    <div class="splitcontentleft field_name">Name </div>
    <div class="splitcontentright"><%= f.text_field :name, :size => 20,    required: true %></div>
  </div>
</div>
<hr />
<%= render :partial => '/inventory_customers/form_custom_fields' %>
    <div></div>
</div>
<div><%= f.submit submit_text %></div>

<% end %>

控制器

before_filter :find_project
...
def edit
    @customer = InventoryCustomer.find(params[:id])
end
...
private
def find_project
    # @project variable must be set before calling the authorize filter
    @project = Project.find(params[:project_id])
end

def customer_params    
    params.require(:inventory_customer).permit(:name, :sap_id, :sap_name, :address, :partner, :partner_text, :active)
end 

错误消息

Started GET "/redmine/projects/inventory development/prototyp/inventory_customers/3/edit" for 172.20.1.197 at 2016-08-03 16:07:45 +0200
Processing by InventoryCustomersController#edit as HTML
Parameters: {"project_id"=>"inventory-development", "id"=>"3"}
Current user: COAH (id=38)
Rendered plugins/prototyp/app/views/_inventory_menu.html.erb (0.7ms)
Rendered plugins/prototyp/app/views/inventory_customers/_form.html.erb (1.6ms)
Rendered plugins/prototyp/app/views/inventory_customers/edit.html.erb within layouts/base (2.9ms)
Completed 500 Internal Server Error in 7ms (ActiveRecord: 0.3ms)

ActionView::Template::Error (No route matches {:action=>"show", :controller=>"inventory_customers", :id=>nil, :project_id=>#<InventoryCustomer id: 3, name: "blub", partner: false, sap_name: "asdasd", address: "sadasd", active: true, sap_id: "">} missing required keys: [:id]):
2: <div class="box tabular">
3: <div class="splitcontent">
4: <div class="splitcontentleft">
5: <%= form_for (@customer) do |f| %>
6:  <div class="splitcontent">
7:          <div class="splitcontentleft field_name">Name </div>
8:          <div class="splitcontentright"><%= f.text_field :name, :size => 20, required: true %></div>
lib/redmine/sudo_mode.rb:63:in `sudo_mode'

如果我删除了form_for,我可以加载编辑视图,但后来我没有看到编辑对象的方法。

由于我刚刚开始使用rails和redmine,我绝对不知道如何修复错误或者我如何能够完成工作。

1 个答案:

答案 0 :(得分:0)

使用form_tag(path, :method=> 'put', :multipart => true ) do代替form_for

路径类似于customer_path 确保使用另一个路径进行编辑(单数)而不是创建(复数,不需要id)