没有保存,没有错误信息 [英] Not saving, no error message

查看:64
本文介绍了没有保存,没有错误信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在提交表单时,它告诉我它已成功创建,但未显示已提交的任何数据.数据库为空.它在实际屏幕上显示空"值,并且在该屏幕上我应该能够编辑数据.这是屏幕截图

On form submission, it's telling me that it was successfully created but it's not showing any data that was submitted. The database is empty. It's showing "null" values and the same on the actual screen where I should be able to edit the data. Here's a screenshot

更新:我认为问题在于它正在发出GET请求,但我不知道如何解决它.这是我单击提交时服务器执行获取操作的屏幕截图

Update: I think the problem is that it's making a GET request but I don't know how to fix it. Here's a screen shot of my server doing a get when I clicked the submit

这是设置

在results_controller.rb的索引操作中,我有

In the index action of results_controller.rb, I have

    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

在models/sex.rb中,没有任何内容...

In models/sex.rb, there is nothing...

class Sex < ActiveRecord::Base
end

这是数据库的设置

推荐答案

问题似乎是您在查看params[:sex]时正在检索params[:blob]. form_for将创建以对象的类命名的字段.您正在使用的实例变量名称@blob是任意的.

It looks like the issue is that you're retrieving params[:blob] when you should be looking at params[:sex]. form_for will create fields named after the class of the object. The instance variable name @blob you're using is arbitrary.

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

这很好地说明了为什么您可能想为实例变量命名.减少混乱.

This is a good argument for why you probably want to name instance variables for what they are. Less confusion.

这篇关于没有保存,没有错误信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆