I use rails with jQuery. a scenario like that
def method_1
respond_to |format|
format.html {}
format.json {return the calculate value}
end
the method recieve a couple of different params, and calculate different value. so when user browser method_1/1 and jQuery code in method_1 view can receive the format.json value, when user browse开发者_如何学运维r method_1/2 and jQuery code in method_1 view can receive the format.json value.
how to?
Looks to me like '1' and '2' are just IDs of some object. If that's the case, this is a simple matter of:
@object = ObjectClassName.find(params[:id])
respond_to do |format|
format.html
format.js { render :json => @object }
end
If the params are not object IDs then you have to clarify what you mean.
精彩评论