내가 레일 코드의이 비트가 호출 할 수 없습니다 :사진 업로드 전무를 반환 보인다 original_filename는
컨트롤러 :
def new
end
def create
the_file = params[:upload][:picture]
@user = User.where("first_name = ?", session[:current_user_id]).first
@photo = Photo.create(:date_time => DateTime.now, :file_name => the_file.original_filename, :user_id => @user.id)
directory = "app/assets/images"
path = File.join(directory, the_file.original_filename)
File.open(path, "wb") do |f|
f.write(the_file.read)
end
redirect_to "photos/index/" + @user.id.to_s
end
및 전망 :
를<% if session[:current_user_id] == nil%>
<p class = "error" >You cannot upload a photo because you are not logged in. Please log in to continue.</p>
<% else %>
<p>
<%= form_tag({action: :create}, multipart: true) do %>
<%= file_field_tag 'upload[picture]' %>
<%= submit_tag("Upload") %>
<% end %>
<% end %>
지금은 nil에 대해 정의되지 않은 메서드 인 [[] '이 표시됩니다. 두 번째 [: picture]가 nil에서 호출 되었기 때문에 NilClass 오류가 발생했을 수 있습니다. params [: photo] [: upload] 등 거의 모든 변형을 시도했지만 항상 params를 nil로 처리하거나 긴 문자열을 반환합니다 (ActionController ... something, 그러나 original_filename을 호출 할 수는 없습니다. 그것도). 무슨 일이 일어나고 있는지에 대한 아이디어는 높이 평가됩니다! 사진이 실제로 업로드되지 않았거나 매개 변수가 잘못되었다고 생각합니다. 단지 어디에 있는지 모르겠습니다.
이 3 또는 4 레일인가 내가보기에 다음을 사용하려고 할 것인가? 대량 할당은 어떻게 처리하나요? –
이것은 레일 4입니다. 질량 할당으로 무엇을 의미하는지 확신 할 수 없습니다 - 바로 옆에있는 문제 일 수 있습니다. – cat
방금 검색했습니다. 레일 4이므로 문제가 아닙니다. – cat