2017-12-03 7 views
0

이 오류의 출처를 찾기 위해 약간의 문제가 있습니다.noMethodError in Property # new

나는이 오류가 무엇입니까 : 나는 확실하지 않다

enter image description here

를, 그것은 문제가 뷰에서 내 폴더의 이름과 관련이있다, 내가 (대신 속성의 ... 그것을 속성을 이름 나는 이미 그것을 변화 시도하지만, 난 여전히

enter image description here

이 내 모델

모습입니다) 오류가 발생
class Property < ApplicationRecord 
    validates :address, presence: true, length: {minimum: 10} 
    validates :price, presence: true 
    validates :description, presence: true 
    validates :bedrooms, presence: true 
    validates :bathrooms, presence: true 
    validates :type, presence: true 
    validates :sqft, presence: true 
    validates :lot, presence: true 
    validates :year_built, presence: true 
end 

이 내 컨트롤러 :

property_controller.rb

class PropertyController < ApplicationController 
    def index 
    @properties = Property.all 
    end 

    def new 
    @property = Property.new 
    end 

    def create 
    @property = Property.new(property_params) 
    if @property.save? 
     flash[:notice] = 'Property was successufully created.' 
     redirect_to property_path(@property) 
    else 
     render :new 
    end 
    end 

    private 
    def property_params 
    params.require(:property).permit(:address, :price, :description, 
:bedrooms, :bathrooms, :type, :sqft, :lot, :year_built) 
    end 
end 

내보기 파일

내가 코멘트 경우 때문에 오류가, 형태와 것 같다
_form.html.erb 
    <% if @property.errors.any? %> 
     <h3>The following errors prevented the addition of this property. 
     </h3> 
     <ul> 


    <% @property.errors.full_messages.each do |msg| %> 
      <li><%= msg %></li> 
     <% end %> 
     </ul> 
    <% end %> 

    <%= form_for @property do |f| %> 
     <div class="form-group"> 
     <%= f.text_field :address, required: true, placeholder: "Address", 
    class: "form-control"%> 
     </div> 
     <div class="form-group"> 
     <%= f.text_field :price, required: true, placeholder: "Price", 
    class: "form-control"%> 
     </div> 
     <div class="form-group"> 
     <%= f.text_area :description, required: true, placeholder: 
    "Description", class: "form-control"%> 
     </div> 
     <div class="form-group"> 
     <%= f.button :submit, class: "btn btn-success" %> 
     </div> 
    <% end %> 

new.html.erb 

    <h3>Add new Property:</h3> 

    <%#= render 'form' %> 

new.html.erb가 잘 표시됩니다. 어떤 도움을 주시면 감사하겠습니다.

레이크 경로 | 그렙 특성

enter image description here

+0

레이크 루트 | grep 속성'? – rony36

+0

확실한 점은 위 이미지를 추가 한 이유는 답변이 너무 길기 때문입니다. 사용자 자원 : 루트를 환영 자원 '# 인덱스를 환영합니다'특성을 끝 – Lucky500

답변

1

명시 적으로 url을 정의하지 않고 form_for를 선언하면, 레일 당신이 원하는 무엇 경로를 추측됩니다. 귀하의 경우 @property은 새로운 인스턴스 (unpersisted)이므로 POSTproperties_path으로 변경하려고합니다. 이것은 단순히 Rails 규칙입니다.

가장 좋은 해결책은 파일 routes.rbresources :properties을 추가하는 것입니다. 파일을 붙여 넣으면 필요한 이유에 대한 정보를 조금 더 제공 할 수 있습니다.

UPDATE

레일 (그러므로 및 경로) 테이블 이름은 모델 이름의 복수로 버전이 될 것으로 기대하고있다. 따라서 Property 모델의 테이블과 경로는 properties입니다. resources :properties (복수형)을 사용하면 레일 규칙을 따르고 모든 것이 잘 작동하도록합시다.

+0

헤이 XML, 나는 Rails.application.routes.draw이 devise_for을 내 routes.rb에 설정해야합니까 : property'를'resources : properties'로 변경했습니다. – Lucky500

+0

변경'자원을 –

+0

그저 완전히 새로운 오류 세트를 줄 것 같습니다. 경로가 [GET]/property/new와 일치하지 않습니다 ... 링크를 변경해야한다고 가정합니다. 안돼. 나는 그것을 시도 할지도 모른다. – Lucky500