Redmine Plugin Development edit form_for

224 Views Asked by At

I am currently developing a redmine Plugin, so far it went well. But since I integrated the plugin into a project i cant use form_for to create an edit view.

Edit View:

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

Controller

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 

Error Message

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'

If i remove the form_for i can load the edit view but then i dont see a way to edit the object.

Since i just started with rails and redmine i have absolutly no idea how to fix the error or how i can do a work arround.

1

There are 1 best solutions below

1
Max B On

Use form_tag(path, :method=> 'put', :multipart => true ) do instead of form_for

path is something like customer_path.
Make sure to use another path for editing (singular) than for creating (plural, no id needed)