# Scriptaculous -- How do I access from Rails?

**URL:** <https://www.ruby-forum.com/t/scriptaculous-how-do-i-access-from-rails/171036>\
**Category:** Rails\
**Created:** [June 25, 2009, 4:32pm UTC](https://www.ruby-forum.com/t/scriptaculous-how-do-i-access-from-rails/171036 "2009-06-25T16:32:56Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![mistressjanna](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/3ab097/32.png) [@mistressjanna](https://www.ruby-forum.com/u/mistressjanna)\
**Post date:** [June 25, 2009, 4:32pm UTC](https://www.ruby-forum.com/t/scriptaculous-how-do-i-access-from-rails/171036/1 "2009-06-25T16:32:56Z")

</div>

If I look at a page with a Scriptaculous example like:

[http://www.gregphoto.net/sortable/advanced/](http://www.gregphoto.net/sortable/advanced/)

And I can view the html/js source of the page – my question becomes,  
how do I implement this, or wire this into, my rails app? -Janna B

---

<div class="post-metadata">

**Author:** ![mistressjanna](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/3ab097/32.png) [@mistressjanna](https://www.ruby-forum.com/u/mistressjanna)\
**Post date:** [June 25, 2009, 5:45pm UTC](https://www.ruby-forum.com/t/scriptaculous-how-do-i-access-from-rails/171036/2 "2009-06-25T17:45:03Z")

</div>

On Jun 25, 3:32 pm, JannaB [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> If I look at a page with a Scriptaculous example like:
> 
> [Drag Drop](http://www.gregphoto.net/sortable/advanced/)
> 
> And I can view the html/js source of the page – my question becomes,  
> how do I implement this, or wire this into, my rails app? -Janna B

You need to , one way or another, generate the javascript that sets up  
the scriptaculous stuff (ie create instances of Sortable for  
appropriate dom elements and so on). There are helpers  
(draggable\_element and so ) that sort of do this for you but  
personally I feel that most of that stuff is a bit of a crutch and  
that you’d be better off biting the bullet and learning enough  
javascript/scriptaculous that you can just write it on your own.

Fred

---

<div class="post-metadata">

**Author:** ![mistressjanna](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/3ab097/32.png) [@mistressjanna](https://www.ruby-forum.com/u/mistressjanna)\
**Post date:** [June 26, 2009, 8:21pm UTC](https://www.ruby-forum.com/t/scriptaculous-how-do-i-access-from-rails/171036/3 "2009-06-26T20:21:13Z")

</div>

Thanks Fred,  
Yes, this is immensely frustrating – I’ve lost 3 days working on  
this, and looking at examples that don;t cut it – there is a vacuum  
of documentation really, and it seems to be a very RoR thing “Yes,  
this is fast and easy to do in RoR with this library/plugin/gem,” but  
when you go to actually do it, you are left with total trial and  
error.

No wonder the dork frameworks like Java Struts are so much more  
prevelant. In truth, those frameworks may just be faster and easier to  
use – I’ve been trying to accomplish things here that frankly don;t  
pay off in terms of the time curve. No one seems to know how to use  
the Scritpatuclous library’s aside from mickey mouse effects.

-Janna B.

On Jun 25, 11:43 am, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![mistressjanna](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/3ab097/32.png) [@mistressjanna](https://www.ruby-forum.com/u/mistressjanna)\
**Post date:** [June 26, 2009, 8:27pm UTC](https://www.ruby-forum.com/t/scriptaculous-how-do-i-access-from-rails/171036/4 "2009-06-26T20:27:04Z")

</div>

And I further agree with you – I think we all need to bite the bullet  
and become js experts rather than depending on Rails to do it for us.  
The problem is, if I look at all this JS that I am seeing in this  
example, I am trying to discern where in my rails app I pick up these  
values? -Janna B.

---

<div class="post-metadata">

**Author:** ![mistressjanna](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/3ab097/32.png) [@mistressjanna](https://www.ruby-forum.com/u/mistressjanna)\
**Post date:** [June 26, 2009, 10:30pm UTC](https://www.ruby-forum.com/t/scriptaculous-how-do-i-access-from-rails/171036/5 "2009-06-26T22:30:07Z")

</div>

Janna, this was mentioned at Railsconf 2009 during the Rails Core  
Panel talk. It was actually the second question from the start of the  
talk. In short, one should understand the underlying technologies  
instead of trying to always abstracting it away.

-Conrad

---

<div class="post-metadata">

**Author:** ![mistressjanna](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/3ab097/32.png) [@mistressjanna](https://www.ruby-forum.com/u/mistressjanna)\
**Post date:** [June 27, 2009, 9:03am UTC](https://www.ruby-forum.com/t/scriptaculous-how-do-i-access-from-rails/171036/6 "2009-06-27T09:03:55Z")

</div>

I agree that there is no way you can use the Rails scriptaculous helpers  
without knowing at least a little of scriptaculous and JavaScript but  
the combination of the docs in these pages isn’t so bad:

[http://api.rubyonrails.org/classes/ActionView/Helpers/ScriptaculousHelper.html#M001927](http://api.rubyonrails.org/classes/ActionView/Helpers/ScriptaculousHelper.html#M001927)  
[http://api.rubyonrails.org/classes/ActionView/Helpers/PrototypeHelper/JavaScriptGenerator/GeneratorMethods.html](http://api.rubyonrails.org/classes/ActionView/Helpers/PrototypeHelper/JavaScriptGenerator/GeneratorMethods.html)  
[http://wiki.github.com/madrobby/scriptaculous](http://wiki.github.com/madrobby/scriptaculous)

I personally used them to build several RoR applications, sometimes  
using the helpers and sometimes writing the JS code as part of larger JS  
functions.

I also agree that the documentation of the Rails helpers could provide  
many more examples, but on the other side they would end up being a  
duplication of the scriptaculous wiki with large chances of introducing  
errors and becoming out of sync with the updates to the library. I  
probably like the way it is now.

Paolo

---

<div class="post-metadata">

**Author:** ![mistressjanna](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/3ab097/32.png) [@mistressjanna](https://www.ruby-forum.com/u/mistressjanna)\
**Post date:** [June 27, 2009, 3:50am UTC](https://www.ruby-forum.com/t/scriptaculous-how-do-i-access-from-rails/171036/7 "2009-06-27T03:50:45Z")

</div>

Exactly – or so I am learning. Look, the scriptaculous stuff. for  
instance, is laden with examples. Trying to do the same thing in  
rails, though purported to be “easier,” and more expeditious, is  
actually a complete pain – the absence of exampls & documentation  
really holds you back and squanders my time. Heneforth, as a matter of  
design philosophy, I think we are FAR better tos stick to html/  
javascript/css and only use rails to tie back into on the server side.

THAT SAID…I am wondering where I tie rails into the source on:

[http://www.gregphoto.net/sortable/advanced/](http://www.gregphoto.net/sortable/advanced/)

and if I cannot tie into it somehow, easily, might as well find a  
different mechanism than RoR – to my way of thinking and my limited  
experience with RoR, if it cannot at least do that easily, it’s  
pointless to pursue as a viable platform for web development. -Janna  
B.

---

<div class="post-metadata">

**Author:** ![mistressjanna](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/3ab097/32.png) [@mistressjanna](https://www.ruby-forum.com/u/mistressjanna)\
**Post date:** [June 27, 2009, 3:03pm UTC](https://www.ruby-forum.com/t/scriptaculous-how-do-i-access-from-rails/171036/8 "2009-06-27T15:03:11Z")

</div>

Thank all of you gentleman very much. As I read your suggestions, it  
occurs to me that I have perhaps not modelled what I need to do  
smartly – and that is making this further complicated. I have a  
number of models which I need t ocombine into a view. For instance, I  
have an players model, which I need to make a list of (batting order)  
(which is what I want to be able to drag into from the team, and out  
of), this list to occur on the left side of the view, and in the  
center, I will put rows containing informations (my info ‘model’  
class) that have occured throughout the game, with various link\_to’s  
in he informations.

So I have all these data models that I must put into one composited  
view. And I am really lost now how one might do this in rails. I do  
not have a model for this compositied view (though, I could make one  
– consistening of two arrays) but then how would I save all this in  
the db (right now I have info and player model) and the fact that the  
data for this composited view doesn;t need to be persisted. This  
really is at the core of my problems here I suppose - and I have no  
idea how to set this up. -Janna B

On Jun 27, 7:16 am, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![mistressjanna](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/3ab097/32.png) [@mistressjanna](https://www.ruby-forum.com/u/mistressjanna)\
**Post date:** [June 27, 2009, 1:17pm UTC](https://www.ruby-forum.com/t/scriptaculous-how-do-i-access-from-rails/171036/9 "2009-06-27T13:17:31Z")

</div>

On Jun 27, 2:49 am, JannaB [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> [Drag Drop](http://www.gregphoto.net/sortable/advanced/)
> 
> and if I cannot tie into it somehow, easily, might as well find a  
> different mechanism than RoR – to my way of thinking and my limited  
> experience with RoR, if it cannot at least do that easily, it’s  
> pointless to pursue as a viable platform for web development. -Janna  
> B.

At the end of the day, Rails is mostly a server side thing. In any  
sensible world your choice of front end tools (javascript libraries  
and so on) doesn’t impact on the backend (be it rails, a php framework  
etc.).

Making a list like that with items from your app doesn’t require big  
chunks of integration. create the html for the list items as you would  
for a completely static display (just ensuring that each element has a  
DOM id). Then you need to run the javascript that will setup the  
scriptaculous side of things. If you want to do exactly what that  
example website does then you might have to generate some javascript  
yourself (rails can make the script tags for you but then you need to  
fill in the blanks), or if what you want is what the scriptaculous  
helpers do then something like

\<%= sortable\_element ‘message\_list’,  
:url =\> sort\_things\_path,  
:complete=\> visual\_effect(:highlight, ‘message\_list’),  
:tag =\> ‘div’%\>

will do the trick.

Fred
