나는이 문제에 대한 해결책을 찾기 위해 지난 3 시간을 보냈고 StackOverflow에서 찾을 수있는 모든 것을 확인했지만 아무 것도하지 않았다. "undefined method
[] '무기 호에 대한 :NoMethodError in BlogsController # create
내가 특별히이 오류가 무엇입니까 NilClass "`
을 그리고 응용 프로그램 추적은 저에게이 제공 : 내가 어떻게 함께 할 수있는 뭔가가 생각
app/controllers/blogs_controller.rb:7:in
create'`을 나는 PARAMS을 전달하고 그러나 나는 무엇이 잘못되었는지 알아낼 수 없습니다 여기 내 컨트롤러 코드입니다 :.
class BlogsController < ApplicationController
def index
@blogs = Blog.all
end
def new
@blog_entry = Blog.new
end
def create
Blog.create(title: params[:blogs][:title], content: params[:blogs][:content])
redirect_to action: 'index'
end
end
가 여기 내 new.html.erb 파일입니다
Started POST "/blogs" for 127.0.0.1 at 2013-06-12 21:54:48 -0700
Processing by BlogsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"cSGH7PgbbFHSSEPV3pJ2LP6V1GvUN10RHRfUDTUXou4=", "post"=>{"title"=>"first entry 5", "content"=>"new entry"}, "commit"=>"Publish"}
[1m[35m (0.1ms)[0m begin transaction
[1m[36mSQL (0.5ms)[0m [1mINSERT INTO "blogs" ("content", "created_at", "title", "updated_at") VALUES (?, ?, ?, ?)[0m [["content", nil], ["created_at", Thu, 13 Jun 2013 04:54:48 UTC +00:00], ["title", nil], ["updated_at", Thu, 13 Jun 2013 04:54:48 UTC +00:00]]
[1m[35m (3.2ms)[0m commit transaction
Redirected to http://localhost:3000/blogs
Completed 302 Found in 5ms (ActiveRecord: 3.7ms)
희망 누군가가 아이디어가있다 : (210)
<%= form_for @blog_entry, as: :post, url: {action: "create"} do |f| %>
Title: </br>
<%= f.text_field :title %> <br />
Content: <br />
<%= f.text_area :content %> <br />
<%= f.submit "Publish", class: "btn btn-primary" %> <br />
<% end %>
여기에 관련 로그 파일입니다. 부디?
아니요, 불행히도 그 중 하나가 작동하지 않습니다. 어떤 오류도 발생하지 않지만 필드에 대해 nil 값을 갖는 레코드를 생성합니다. –
나는 또한 같은 nil 결과를 가진 Blog.create (params {: blog_entry])를 사용해 보았습니다. –
콘솔 로그는 제출 버튼을 누르십시오. – rmagnum2002