我可以将实例变量发送到 Tequila (.jazz) JSON 解析器吗? (Ruby on Rails)
我正在使用很棒的 Tequila-JSON 解析器 ( http://github.com/inem/tequila )一个 Web 应用程序,用于呈现或多或少复杂的 JSON 服务器回复。越来越多的 JSON 模板 (.jazz) 以某种方式在真正的“视图”中增长。我现在正在尝试从相应的控制器获取实例变量到 .jazz 模板中,但这不知何故失败了。
这就是我正在尝试做的事情。
控制器
def get_userlist
@users = User.find(:all, :order => "value DESC", :limit => 10)
@user = User.find_by_email(params[:user_email])
@userid = @user.id # also tried: @userid = 2
respond_to do |format|
format.json
end
end
.jazz 视图:
-@users
:only
.nickname
.level
.user_icon_url
.email
:methods
.isfriend(@userid)
+last_checkin
+last_checkin_place
:only
.name
.city
这一切都返回一个非常有效的 JSON 服务器回复,但不幸的是,方法“isfriend”存在问题
:methods
.isfriend(@userid)
位于模型“User”中,成功调用并返回 JSON,什么它应该。 但是实例变量的值在某种程度上是错误的。与上面的相反,这个工作得很好:
:methods
.isfriend(1)
现在的问题是:龙舌兰酒不能解释它自己的 .jazz 模板中的实例变量吗?有谁有经验、解决方案或解决方法吗?
为了完整起见,这里是用户模型的 isfriend 方法:
def isfriend(user_id)
"Hi, I am User with the id: " + user_id.to_s
end
I am using the great Tequila-JSON Parser ( http://github.com/inem/tequila ) in an Web-application, to render more or less complex JSON server-replies. More and more the JSON-Templates (.jazz) are growing in somehow real "views". I am trying now, to get an instance-variable from the according controller, into the .jazz template, but this somehow fails.
Here is what I am trying to do.
The controller
def get_userlist
@users = User.find(:all, :order => "value DESC", :limit => 10)
@user = User.find_by_email(params[:user_email])
@userid = @user.id # also tried: @userid = 2
respond_to do |format|
format.json
end
end
The .jazz view:
-@users
:only
.nickname
.level
.user_icon_url
.email
:methods
.isfriend(@userid)
+last_checkin
+last_checkin_place
:only
.name
.city
This all returns a pretty valid JSON server-reply, but unfortunately, there is a problem with the
:methods
.isfriend(@userid)
The Method "isfriend" resides in the model "User", is called successfully and returns in the JSON, what it should. But the value of the instance-variable somehow is wrong. Opposed to the above, this one works fine:
:methods
.isfriend(1)
Now the question: Is Tequila not able, to interpret instance-variables in its own .jazz templates? Does anyone have experience, solutions or workarounds?
For the sake of completeness, here is the isfriend method of the User-Model:
def isfriend(user_id)
"Hi, I am User with the id: " + user_id.to_s
end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
没有。而且它在 Rails 3 上不起作用。我只花了 6 个小时尝试移植它,但基本上一无所获:-(
Nope. Also it doesn't work on Rails 3. I just spent 6 hours trying to port it and got basically nowhere :-(