views:

37

answers:

1

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 browser method_1/2 and jQuery code in method_1 view can receive the format.json value.

how to?

A: 

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.

Samo