不节能,没有错误信息(Not saving, no error message)

2019-10-31 13:12发布

在表单提交,它告诉我,这是成功创建,但它没有显示已提交的任何数据。 该数据库是空的。 它显示“空”值与实际屏幕,在这里我应该能够编辑数据上是相同的。 下面是截图

更新:我认为问题是,它使一个GET请求,但我不知道如何解决它。 这里是我的服务器的截屏做一个GET当我点击提交


这里的设置

在results_controller.rb的指标作用,我有

    def index
    @results = Result.all
    @blob = Sex.new            //==@blob = Sex.new is the one I'm focussing on...
    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @results }


    end
  end

在视图/结果/指数,我有如下形式

<`%= form_for(@blob) do |f| %>`

<div class="field">
    <b>1. solicitor exam was fixed?:</b><br/>
    <%= f.label(:solicitorcurve, "it was cooked") %>
    <%= f.radio_button(:solicitorcurve, "t") %> </br>
  </div>  
  <div class="field">

   <%= f.label(:solicitorcurve, "no it was ok") %>
    <%= f.radio_button(:solicitorcurve, "f") %>
   </div>  

    <div class="field">
    <%= f.label(:draftingteach, "i give the teaching a grade of _ on a scale of 1 to 6") %>
    <%= f.select:draftingteach, 1..6 %> </br>
    </div>

在sexes_controller.rb的创造作用,我有

def create

    @sex = Sex.new(params[:blob])
    respond_to do |format|
      if @sex.save
        format.html { redirect_to(@sex, :notice => 'Sex was successfully created.') }
        format.xml  { render :xml => @sex, :status => :created, :location => @sex }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @sex.errors, :status => :unprocessable_entity }
      end
    end
  end

在模型/ sex.rb,有什么...

class Sex < ActiveRecord::Base
end

这是数据库的建立

Answer 1:

它看起来像问题是,你检索params[:blob]当你应该看params[:sex]form_for将创建该对象的类的名字命名的领域。 实例变量名@blob你使用是任意的。

...
@sex = Sex.new(params[:sex])
...

这就是为什么你可能想命名实例变量,它们是什么一个很好的理由。 减少混乱。



文章来源: Not saving, no error message