当我提交表单时,我收到一个错误:缺少模板letsgos/create, application/create with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :raw, :ruby]}
.
我不明白为什么当 create 的视图是from _form.html.erb
. 我不需要制作 /create 文件。我在这里错过了什么吗?
letsgos_controller.rb:
before_action :signed_in_user, only: [:create, :destroy]
def create
@letsgo = current_user.letsgos.build(letsgo_params)
if @letsgo.save
flash[:success] = "Date posted!"
redirect_to root_url
end
def destroy
@letsgo.destroy
redirect_to root_url
end
用户控制器:
def show
@user = User.find(params[:id])
@letsgos = @user.letsgos.paginate(page: params[:page])
@letsgo = current_user.letsgos.build if signed_in?'
end
Letsgo.rb:
belongs_to :user
default_scope -> { order('created_at DESC') }
validates :content, presence: true, length: { maximum: 360 }
validates :tag, presence: true
validates :user_id, presence: true
end
/users/show.html.erb:
<% if @user.letsgos.any? %>
Dates (<%= @user.letsgos.count %>)
<%= render @letsgos %>
<%= will_paginate @letsgos %>
<% end %>
/letsgos/_form.html.erb
<%= form_for(@letsgo) do |f| %>
<div class="field">
<%= f.text_area :content, placeholder: "Propose new date..." %>
</div>
<%= f.submit "Post", class: "btn btn-large btn-primary" %>
<% end %>
/letsgos/home.html.erb:
<% if signed_in %>
<% render 'letsgos/form' %>