Jump to content

The ultimate community for Ruby on Rails developers.


Photo

Return Validation error from multiple objects

Validation multiple objects

  • Please log in to reply
No replies to this topic

#1 ramita.vijay

ramita.vijay

    Passenger

  • Members
  • 1 posts

Posted 01 November 2013 - 01:19 PM

I have a form that have text fields mapped to two different objects: story and story_set. I am submitting the form using ajax and sending it to stroies_controller. When the form is submitted, and some input is missing from story, only those fields are marked in error. I am rendering the response as follows:

 

  respond_to do |format|
      if @story.save
        format.json{ render :json=> {:success => "true", :story_id => @story.id } }
        format.html { redirect_to("/stories?filter=" + @story.story_set_id.to_s, :notice => 'Story was successfully created.') }
        format.xml  { render :xml => @story, :status => :created, :location => @story }
      else
 
        format.json{ render :json=> @story.errors }
        format.html { render :action => "new" }
        format.xml  { render :xml => @story.errors, :status => :unprocessable_entity }
      end
    end
 
What should I write so that validation error from stroy_set is also sent to the form.
 
 






Also tagged with one or more of these keywords: Validation, multiple objects

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users