开发者

Is it possible to render a view in XML or JSON using ruby

开发者 https://www.devze.com 2023-02-17 18:38 出处:网络
Rendering a JSON or XML view in rails 3 is straight forward enough.As Hobo does not use views, I cannot wor开发者_JS百科k out how to do the same in a hobo project and the docs are not very illuminatin

Rendering a JSON or XML view in rails 3 is straight forward enough. As Hobo does not use views, I cannot wor开发者_JS百科k out how to do the same in a hobo project and the docs are not very illuminating. Has anyone done this?

I am using rails 3.0.3 and hobo 1.3.0 pre29


The right solution is:

def show
    hobo_show do |expects|
      expects.json { render :json => @user.to_json }
      expects.html { hobo_show }
    end
end

for index:

def index
    hobo_index do |expects|
      expects.json { render :json => @users.to_json }
      expects.html { hobo_index }
    end
end


I haven't done it in a Rails3/Hobo1.3 project yet, but I've certainly rendered non-DRYML views in Hobo projects. It should work exactly the same as in Rails.

However, for JSON or XML I usually just do it in the controller:

def show
 respond_to do |expects|
   expects.json { render :json => {...} }
   expects.html { hobo_show }
 end
end
0

精彩评论

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