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
精彩评论