开发者

Turn a partial into a json variable in the controller

Hi I need to turn the html of a partial into a json object (NO开发者_运维问答T TO BE RENDERED), but to be stored in a seperate format.

Something like this:

  @json = (:partial => "/answers/likers" ,:type => :html)

Although the above obviously does not work, but hope you get the point, thanks!


Try render_to_string. It takes the same arguments as render, and just returns a string instead of outputting the data.

It looks like it's being deprecated but I can't find any new method that provides that same functionality for Rails 3. I tested it on a local Rails 3 setup, though, and it works for me. If anyone knows the "new" way to do this in Rails 3 please let me know, I'm interested now :)


Rails has a .to_json function. However, I never used this together with a partial ...

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜