ruby on rails 4 - NoMethodError (undefined method `[]' for nil:NilClass) Post Attachments issue -
i getting error , not sure why. post still saved database, though throws , error. has post_attachments, not sure how fix it. appreciated!
here postcontroller create method error:
def create @trail = trail.find(params[:trail_id]) @post = current_user.posts.build(params.require(:post).permit(:body, post_attachments_attributes: [:id, :post_id, :gallery])) @post.trail = @trail @new_post = post.new authorize @post if @post.save params[:post_attachments]['gallery'].each |a| @post_attachment = @post.post_attachments.create!(:gallery => a, :post_id => @post.id) end flash[:notice] = "post saved!" redirect_to @post.trail else flash[:error] = "error creating post. please try again." render :new end
end
the error occurs on line params[:post_attachments]['gallery'].each |a|
Comments
Post a Comment