강사라는 두 가지 모델이 있으며 관련 요청을 함께 처리합니다. 강사에게 속한 요청을 제출하고 싶지만 콘솔에서 다음 오류가 표시됩니다. 누군가 나를 도울 수 있습니까?. 그것 (때문에 save
반환 false
)를 리디렉션하지 않도록 감사합니다,레일에 양식을 제출할 수 없습니다
Processing by RequestsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"SaLDbXaZOy2cvGILrC9IJ7vInkF0xG42bf84k3IcDj+eFN9lTRfZlkGUMr8s82zQEdO9dgJ3Set935RGH8uv9w==", "request"=>{"name"=>"dsada", "email"=>"dsadas", "phone"=>"sadsadd", "message"=>"sadsa"}, "commit"=>"Create Request"}
(0.1ms) begin transaction
(0.1ms) rollback transaction
No template found for RequestsController#create, rendering head :no_content
Completed 204 No Content in 38ms (ActiveRecord: 0.3ms)
요청 양식
<hr>
<%= simple_form_for([@request, @instructor.requests.build], :url =>{ :controller =>"requests",
:action => "create" }) do |f| %>
<%= f.input :name, label: "Your name" %>
<%= f.input :email %>
<%= f.input :phone, label: "Phone number" %>
<%= f.input :message, as: :text %>
<br>
<%= f.button :submit, class: "btn btn-danger" %>
<% end %>
<br>
<br>
요청 컨트롤러
class RequestsController < ApplicationController
def index
if params[:search].present?
@instructors = Instructor.near(params[:search], 50)
else
# Shows all listed instructors by the created date.
@instructors = Instructor.order('created_at DESC')
end
end
def show
@instructor = Instructor.find(params[:id])
end
def create
@request = Request.new(request_params)
if @request.save
redirect_to "root"
end
end
private
def request_params
params.require(:request).permit(:name, :email, :phone, :message)
end
end
나는 왜 그 false를 반환하는지 잘 모르겠다. 또한 여전히 (0.1ms) 거래 시작 (0.1ms) 롤백 트랜잭션 – Faisal
귀하의 모델을 볼 수 없으므로 어떤 유효성 검사인지 말할 수 없습니다. 'dsadas'는 유효한 이메일이 아님을 짐작할 수 있습니다. – MikDiet
아직 유효성을 검증하지 않았습니다! 그 유일한 (요청) belongs_to : 강사 및 강사 has_many : 요청 – Faisal