Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I've ruby script as part of rails application which is used to copy files from some directory to another inside the server. I am using Dojo as front-end. I've a dojo widget which is displaying a button fine. Now I want to the script to be executed when I click the Dojo button.

Wigdet extract:

<input type="button" data-dojo-type="dijit.form.Button" dojoAttachEvent="_onClick:copyfiles" label="Copy Files"></input>

JavaScript function part of widget:

copyfiles: function() {
window.location = '/files/copy_files'
}

in routes I have:

resources :files do
get :copy_files

and in files_controller I have:

def copy_files
  fc = FilesCopier.new
  source = '/home/myname/sourcefiles'
  dest = '/home/myname/backup'
  fc.copy_files(source,dest)
end

But when I clicked the button nothing happens. I've also tried running the code inside a view but nothing happens.

share|improve this question
    
Do any JS errors pop up in your dev console? What does your Rails log tel you, is the route being hit? –  Novae May 9 '13 at 16:28
    
I don't get any error. Path is actually loaded http/1.1 OK so no problem there. –  zulq May 9 '13 at 17:17
    
Does your copy_files method work, if you call it for example directly in your console? –  Mattherick May 10 '13 at 10:24
    
The method works perfect. Now even If i put it on the main page it will be executed. –  zulq May 10 '13 at 10:55

1 Answer 1

up vote 0 down vote accepted

I've resolved it. All I have to do was to change the routes file as per below:

put :copy_files, :on => :collection

And now even if I put it on show method inside the controller it will work.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.