Note that there are some explanatory texts on larger screens.

plurals
  1. POrouting error after failed validation on create
    text
    copied!<p>Ok, the issue has changed. The different behaviour between an invalid create and update on a work instance was due to a missing collection referenced in the rendered _form.html.erb.</p> <pre><code>@operations = @work.work_ticket.part.operations </code></pre> <p>I have added this collection in the create action before it renders the "new" action. I then expected the "new" view to render with the invalid fields highlighted.</p> <p>But now there is a new error. I get No route matches {:controller=>"works"}. THis seems strange as all the routes for the works model work, including the new action except when it is navigated to after failed save/validation step.</p> <p>Here are the routes available:</p> <pre><code> works GET /works(.:format) works#index POST /works(.:format) works#create new_work GET /works/new(.:format) works#new edit_work GET /works/:id/edit(.:format) works#edit work GET /works/:id(.:format) works#show PUT /works/:id(.:format) works#update DELETE /works/:id(.:format) works#destroy </code></pre> <p>the create action calls render "new" in the works controller s below:</p> <pre><code># POST /works # POST /works.json def create @work = Work.new(params[:work]) @operations = @work.work_ticket.part.operations respond_to do |format| if @work.save format.html { redirect_to @work, notice: 'Work was successfully created.' } format.json { render json: @work, status: :created, location: @work } else format.html { render action: "new" } format.json { render json: @work.errors, status: :unprocessable_entity } end end end </code></pre> <p>The create action fails on the save method and re-routes to the new action, causing runtime errors.</p> <p>I dont understand why update validates correctly and create doesn't.</p> <p>Validation lines in the model are as follows: </p> <pre><code>validates :start, :presence =&gt; { :message =&gt; "must be a valid date/time" } validates :end, :presence =&gt; {:message =&gt; "must be a valid date/time"} validate :start_must_be_before_end_time def start_must_be_before_end_time errors.add(:start, "must be before end time") unless self.start &lt; self.end end </code></pre> <p>Any pointers would be great.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload