41

I've already asked the question on the Redmine official website but I didn't get any answer, maybe I'll have more chance here.

I'm working on a project and I try to improve an existing plugin for Redmine by adding some features to it to allow the user to upload his Dropbox files in the Redmine documents with a simple form. Redmine already has this possibilty so I would like to use the controller and methods already defined in the Redmine source code.

I have the following code in one of my plugin views:

<% html_title "Reddrop - Sync" %>
<h2>Synchronisation page</h2>
<p>Please choose your file</p>
<%= form_tag({:controller => "documents", :action => "add_attachment", :id => @document},    :multipart => true) do %>
<%= file_field_tag 'attachments[dummy][file]', :id => nil, :multiple => true, :onchange => "addInputFiles(this)" %>
<%= submit_tag(value = "Sync this file with Redmine") %>
<% end %>

I'm calling the "documents" controller and the add_attachment method which are defined in the Redmine source code. When I submit my form I get the following error:

ActionController::RoutingError (No route matches {:controller=>"documents", :action=>"add_attachment", :id=>nil}):

Is it possible to call these controllers/methods through a plugin if they are defined in the Redmine source code?

If yes, maybe could you give some advice to how configure my routes?

Bryan Ash
  • 4,385
  • 3
  • 41
  • 57
Shredator
  • 940
  • 3
  • 17
  • 32
  • 4
    Your `@document` instance variable is `nil`. How do you set it? – Marek Lipka Mar 07 '14 at 10:12
  • Mmh there are probably some mistakes in the code, because I'm unable to try it. I can't answer you precisely now, let me check the full code. – Shredator Mar 07 '14 at 10:32
  • 1
    Since it's not really an answer, I figured I'd just link to a plugin I wrote a while back that uses dropbox as Redmine's file storage backend. https://github.com/alexbevi/redmine_dropbox_attachments. Without more context, it's a bit difficult to provide a proper answer. If you have a fork on Github you could point to so we could test it might be easier to answer this question. – Alex B. May 05 '14 at 20:04
  • I found another way to upload my files, and it's working pretty well but thanks for the link, I will for sure take a look. – Shredator May 07 '14 at 07:22
  • 4
    well maybe the controllers are namespaced, try running `rake routes` and see what the routes are called and if they have namespaces or not. – Mohammad AbuShady Aug 30 '14 at 18:06
  • Basically you need to recreate the `documents_controller.rb` on your project with the same path as the original one. I did the same to overwrite doorkeeper's controller. If the path is not exactly the same, you'll have a `No route matches` error. – brcebn Jul 28 '15 at 21:56

2 Answers2

1

See here :id => @document
@document is the variable that contains nil however this should contain some id (like 1,2 or whatever) of required record check it in your controller and once you will fix this issue sure this error will be resolved.

Jai Chauhan
  • 4,035
  • 3
  • 36
  • 62
0

validate route format rake | rails route

send the expected parameters and the correct namespace. If you already have a @document you could use the form_for.

`<% form_for(@document, url: {action:'add_attachment'} ) do %> `
JBG
  • 1
  • 2