3

I'm upgrading a rails project from 3.2 to 5.2. The docs in prototype-rails [github][1] say the support is not confirmed for Rails 4.1 and above. But right now, in the process of upgrading I'm still in Rails 4.0.13 and the gem no longer works.

I'm not very familiar with Prototype RJS and Scriptaculous which seem to be what the gem adds to rails project.

What is the best way to replace this gem and maintain the RJS functionality?

Has anyone had to do it and what solution have you found to be the most effective?

UPDATE

Sorry folks. Project long past and been inactive. The way I managed to get past this was by getting rid of the gem and adding the code for prototype under vendor and then requiring it in my application.js under assets.

By adding the two files below to my project and requiring them, as I mentioned above, I managed to get it working.

https://github.com/rails/prototype-rails/blob/master/vendor/assets/javascripts/prototype_ujs.js

https://github.com/rails/prototype-rails/blob/master/vendor/assets/javascripts/prototype.js

So in my project now I have:

vendor/assets/javascripts/
  prototype.js
  prototype.ujs.js

and in my assets/javascripts/application.js I required those files after jquery

//= require prototype
//= require prototype_ujs

I did have to make some changes to my views too. They ware using .js.rjs extensions. I turned them into .js.erb and made the necessary syntax changes to get it working.

Something like this

page.replace_html 'info', :partial => 'shared/info'
page['info'].show

Was refactored into this

$info.update(
    "<%=
      escape_javascript(
        render(
          partial: 'shared/info'
        )
      )
     %>"
);
$info.show();

Hope it helps.

vinibol12
  • 468
  • 4
  • 21
  • 2
    Did you found an alternative? – AkashP Jan 30 '20 at 11:31
  • 1
    I am upgrading rails app from 4.2 to 5 and I am using prototype-rails gem. Looking for a way to replace this gem. – harika Oct 09 '20 at 21:17
  • 1
    Same issue, has anyone tried to make this work? – Jonathan Swartz Feb 16 '21 at 20:02
  • Hey guys...sorry been inactive for a while. The way I managed to get this working was by throwing away the gem and manually adding the code of `prototype.js` and `prototype_ujs.js` under `vendor/assets/javascripts` and then requiring it manually in my `app/assets/javascripts/application.js`. – vinibol12 Mar 01 '21 at 20:47

0 Answers0