开发者

send params with a =render :partial in rails

in my view, I use content_for to load a partial (a javascript file). I'd like to pass a rails variable into the js file. Is there a way to do this?

Right now, I have this in the view:

-content_f开发者_StackOverflow社区or (:scroller) do
 =render :partial => '/images/public/scrollerJs'

What I want is something like this:

-content_for (:scroller) do
 =render :partial => '/images/public/scrollerJs', :params => #{@images}

My js file _scrollerJs.erb begins like this

var ScrollerObject = Class.create();
 Object.extend(ScrollerObject.prototype, {
 initialize: function() { ... }
  ...

Where would I pick up the param? I hope this makes sense. Thanks!


Let's say you have a local object called images in your partial, that you then manipulate. The way to pass data to that local object is like this

render :partial => '/images/public/scrollerJs', :images => @images
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜