我刚做了一个rails g scaffold Feedback feedback:string user_id:integer
。当我转到 0.0.0.0:3000/feedbacks/new 时,一切正常。但是当我尝试将反馈表单放入模态框时,我收到了这个错误:undefined method "model_name" for NilClass:Class
. 我已经用谷歌搜索了这个问题,但找不到有效的解决方案。
有人知道这可能是什么解决方案吗?
反馈/_form.html.erb(我使用 simple_form)
<%= simple_form_for(@feedback) do |f| %>
<%= f.error_notification %>
<div class="form-inputs">
<%= f.input :feedback %>
<%= f.input :user_id %>
</div>
<div class="form-actions">
<%= f.button :submit %>
</div>
<% end %>
反馈/new.html.erb
<h1>New feedback</h1>
<%= render 'form' %>
<%= link_to 'Back', feedbacks_path %>
反馈/_feedback_modal.html.erb
<div id="activate_feedback_modal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-body">
<%= render "feedbacks/form" %>
</div>
</div>
feedbacks_controller.rb(new
和create
动作)
class FeedbacksController < ApplicationController
def new
@feedback = Feedback.new
respond_to do |format|
format.html # new.html.erb
format.json { render json: @feedback }
end
end
def create
@feedback = Feedback.new(params[:feedback])
respond_to do |format|
if @feedback.save
format.html { redirect_to @feedback, notice: 'Feedback was successfully created.' }
format.json { render json: @feedback, status: :created, location: @feedback }
else
format.html { render action: "new" }
format.json { render json: @feedback.errors, status: :unprocessable_entity }
end
end
end
end
lelist.html.erb(我渲染模态的地方)
<div class="lelist_body">
<div class="container" id="dk">
<% if current_user %>
<div class="row">
<div class="span6 offset3" id="user_post_area_button">
<a class="big_fat_feedback_button" href="#activate_feedback_modal" data-toggle="modal">feedback</a>
</div>
</div>
<% end %>
<%= render 'pages/singlePost' %>
</div>
<div class="row">
<div class="span6 offset3">
<%= will_paginate @posts %>
</div>
</div>
</div>
<%= render "feedbacks/feedback_modal" %>