简体   繁体   English

发送带有= render:partial in rails的参数

[英]send params with a =render :partial in rails

in my view, I use content_for to load a partial (a javascript file). 在我看来,我使用content_for加载了部分文件(一个javascript文件)。 I'd like to pass a rails variable into the js file. 我想将rails变量传递到js文件中。 Is there a way to do this? 有没有办法做到这一点?

Right now, I have this in the view: 现在,我认为:

-content_for (: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 我的js文件_scrollerJs.erb像这样开始

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. 假设您在局部中有一个称为images的本地对象,然后可以对其进行操作。 The way to pass data to that local object is like this 将数据传递到该本地对象的方式是这样的

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM