Tell me more ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

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
share|improve this question
1  
I don't understand, you are already using respond_with, what's the problem? the error branches? anyway, note that second branch of the conditional is never reached: if @confirm is set to a non-nil value, it will go to the first one. – tokland Jun 8 '12 at 15:53

1 Answer

You just have to set the content type header from your curl request.

curl --data "<xml>" \ 
     --header "Content-Type: text/xml" \
     --request subscriptions/create \
     localhost:3000
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.