2016-06-27 2 views
0

form_for를 사용하여 레일스에 새 개체를 만들려고합니다. 어떤 이유로 개체를 데이터베이스에 저장할 수 없습니다. 아래를 참조하십시오데이터베이스에 개체가 저장되지 않습니다.

모델 :

class Property < ActiveRecord::Base 
    has_many :units 
end 

보기 : new.html.erb

<form> 
    <div class="form-group"> 
    <div class = "row"> 
     <div class="col-md-8"> 

     <%= form_for (@property) do |f| %> 

      <%= f.label :property_name %> 
      <%= f.text_field :property_name, class: 'form-control', placeholder:"Please enter property name here" %><br/> 

      <%= f.label :property_address %> 
      <%= f.text_field :property_address, class: 'form-control' %><br/> 
     </div> 
    </div>  
    </div> 
    <%= f.submit "Add Building"%> 
    <% end %> 
</form> 

컨트롤러 :

여기
def new 
    @property = Property.new 
    end 

    def create 
    @property = Property.new(property_params) 
    if @property.save 
     flash[:success] = "Property created" 
     redirect_to root_path 
    else 
     flash[:error] = "Property was not created" 
     render new_property_path 
    end 
    end 
private 
    def property_params 
     params.require(:property).permit(:property_name, :property_address) 
    end 

Parameters: {"utf8"=>"✓", "authenticity_token"=>"VNad0+BD6TAavWiSCSX12Ob6ilU+DrzDv0O/d++af1+s6BtQkC2hKUUINaPXhk1hWA5Qfa6JV0RwkpAlx8IwKg==", "property"=>{"property_name"=>"test 934", "property_address"=>""}, "commit"=>"Add Building"} 
를 생성 PARAMS입니다
+0

도움이되기를 바랍니다? –

답변

1

보기에 추가 FORM 태그가있는 것 같습니다. 양식은 HTML로 중첩 될 수 없습니다. 내부에서이 양식을 삭제해야합니다.

<form> 
    <div class="form-group"> 
.. 
.. 
</form> 

이 블록은 조치 및 방법 세트가있는 양식을 생성합니다. 따라서이 여분을 제거하면 작동합니다.

<%= form_for (@property) do |f| %> 

은 = '포스트'행동 양식 방법을 생성 = '/ 속성'

이 오류가 무엇을 얻고되는

관련 문제