1

I have a static Greasemonkey script and it works fine. I have a rails 4 application, and I just want to customize my script for current user. My problem is I can render the script named script.user.js, but the content type is always text/html and Greasemonkey can't detect it for install.

Here few lines of code :

routes.rb

resources :users do
    get 'script.user.js', :action => 'script', :on => :collection
end

users_controller.rb

def script
    render file: 'users/script.user.js', content_type: "application/x-javascript"
end

How do I get my app to serve this file with the right type?

Brock Adams
  • 90,639
  • 22
  • 233
  • 295
Florent L.
  • 403
  • 4
  • 10

1 Answers1

2

Try (untested):

def script
    render file: 'users/script.user.js', content_type: Mime::JS
end

Similar problem and answers: "Rendering file with MIME Type in rails".

Also, from OP comment (I should have remembered this): Clear your browser cache to let the new association take effect.

Community
  • 1
  • 1
Brock Adams
  • 90,639
  • 22
  • 233
  • 295
  • Thank you ! This work ! At the end, my first code worked too, it seems I needed to clear recent history of my browser... Anyway, my solution, your solution and your link works perfectly ! Thanks again ! – Florent L. Oct 06 '13 at 16:21