The following code validates a PIN given to the user against a Subscription object. Since It does not respond_with(@confirm) it broke when doing POST using JSON with curl. How could I simplify this to respond to :html, :json, :xml.
respond_to :html, :json, :xml
def new
@confirm = Subscription.new
end
def create
@keyword = Keyword.joins(:shortcode).where("shortcodes.shortcode = ? and shortcodes.country = ?",params[:subscription][:shortcode],params[:subscription] [:country]).find_or_create_by_keyword(params[:subscription][:keyword])
if @confirm = Subscription.where(:phone => params[:subscription][:phone], :country => params[:subscription][:country], :keyword_id => @keyword.id).last
@confirm.check_subscription_pin(params[:subscription][:pin])
respond_with(@confirm)
elsif @confirm && @confirm.errors.any?
flash[:notice] = @confirm.errors
render :action => :new
else
flash[:notice] = "Subscription not found."
render :action => :new
end
end
@confirmis set to a non-nil value, it will go to the first one. – tokland Jun 8 '12 at 15:53