Rails 4.2
Ruby 2.5
在我的routes.rb中,我有:
shallow do
resources :organizations do
resources :organization_notes
end
end
产生以下路线:
new_organization_organization_note GET /organizations/:organization_id/organization_notes/new(.:format) organization_notes#new
在我的organization_notes_contoller.rb中,我有:
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
这是我用于新控制器操作的链接:
link_to 'Add Note', new_organization_organization_note_path(@organization.id), :class => "btn btn-primary btn-lg"
在我的views / organization_notes / _form.html.erb中,我有:
<%= 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 %>
但是,当我点击链接时,我收到以下错误消息:
Incomplete response received from application
在日志文件中:
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)
有什么想法吗?