0
Rails 4.2
Ruby 2.5

In my routes.rb, I have:

shallow do
  resources :organizations do
    resources :organization_notes
  end
end

Which produces the following route:

new_organization_organization_note GET /organizations/:organization_id/organization_notes/new(.:format) organization_notes#new          

In my organization_notes_contoller.rb, I have:

def new
  organization = Organization.find(params[:organization_id])
  @organization_note = organization.organization_notes.build
  respond_to do |format|
    format.html # new.html.erb
    format.json { render json: @organization_note }
  end
end

def create
  organization = Organization.find(params[:organization_id])
  @organization_note = organization.organization_notes.create(params[:organization_note])
  respond_to do |format|
    if @organization_note.save
      format.html { redirect_to([@organization_note.organization, @organization_note], notice: 'Organization Note was successfully created.') }
      format.json  { render json: @organization_note, status: :created, location: [@organization_note.organization, @organization_note] }
    else
      format.html { render :action => "new" }
      format.json { render json: @organization_note.errors, status: :unprocessable_entity }
    end
  end   

This is the link I am using for the new controller action:

link_to 'Add Note', new_organization_organization_note_path(@organization.id), :class => "btn btn-primary btn-lg"

In my views/organization_notes/_form.html.erb, I have:

<%= bootstrap_form_for(@organization_note, layout: :horizontal, label_col: "col-sm-2", control_col: "col-sm-10") do |f| %>
  <%= f.error_notification %>

  <div class="form-inputs">
    <%= f.text_area :note, :rows => 5, :cols => 120  %>
  </div>

  <p>
    <%= f.form_group do %>
      <%= f.submit "Save Note", class: "btn btn-primary" %>
    <% end %>
  </p>

<% end %>

But, when I click on the link, I get the following error message:

Incomplete response received from application

And in the log file:

Started GET "/organizations/223/organization_notes/new" for xx.xxx.xxx.xxxx at 2018-04-02 13:01:01 +0000
Processing by OrganizationNotesController#new as HTML
  Parameters: {"organization_id"=>"223"}
  [1m[36mUser Load (0.1ms)[0m  [1mSELECT  `users`.* FROM `users` WHERE `users`.`id` = 1  ORDER BY `users`.`id` ASC LIMIT 1[0m
  [1m[35mOrganization Load (0.1ms)[0m  SELECT  `organizations`.* FROM `organizations` WHERE `organizations`.`id` = 223 LIMIT 1
Completed 500 Internal Server Error in 8ms (ActiveRecord: 0.4ms)    

Any ideas?

EastsideDev
  • 6,257
  • 9
  • 59
  • 116
  • 1
    The problem has nothing to do with your routes. Maybe this can help https://stackoverflow.com/questions/29241053/incomplete-response-received-from-application-from-nginx-passenger – chumakoff Apr 02 '18 at 14:22
  • No. The app is loading fine. It's only the actions related to this nested resource that's the problem – EastsideDev Apr 02 '18 at 15:32
  • can you put a `byebug` after `@organization_note = organization.organization_notes.build` to check the error in controller or view? – 王信凱 Apr 02 '18 at 15:57

0 Answers0