开发者

send params with a =render :partial in rails

开发者 https://www.devze.com 2023-01-27 03:37 出处:网络
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?

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

精彩评论

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