このエラーがどこから来たのかを見つけるには少し問題があります。プロパティのnoMethodError#new
私はこのエラーを取得しています:私が代わりにプロパティの...それをプロパティの名前
私はわからない、それは問題はビューで私のフォルダの命名に関係しています、(これは私のモデルは
のように見えるものである)私はすでにそれを変更しようとしたが、私はまだエラーが出ます
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はうまく表示されます。どんな助けもそれに感謝します。
レーキルート| grepのプロパティ
あなたは 'rake routes | grepプロパティ '? – rony36
確かに、私は上の画像を追加しました。なぜなら、答えが長すぎたからです。 – Lucky500