保险中的NoMethodError #new

时间:2015-09-01 19:47:43

标签: ruby-on-rails ruby

我需要第二双眼睛。我不太确定我错过了什么。

我创建了一个新的脚手架rails generate scaffold Insurance string:name,然后是rake db:migrate。但是,当我转到新创建的页面并选择“新保险”时,我收到以下错误消息。

保险中的

NoMethodError #new显示/home/ubuntu/workspace/app/views/insurances/_form.html.erb第5行引发: #dextracted源的未定义方法“保险”(第5行附近):

<div class="form-group">
      <%= f.label :insurance %><br>
      <%= f.text_field :insurance, class: "form-control" %>
    </div>
    <div class="actions">
      <%= f.submit class: "btn btn-primary" %>

我确信这很容易我只是看不到它。

保险经理:

class InsurancesController < ApplicationController
  before_action :set_insurance, only: [:show, :edit, :update, :destroy]

  respond_to :html

  def index
    @insurances = Insurance.all
    respond_with(@insurances)
  end

  def show
    respond_with(@insurance)
  end

  def new
    @insurance = Insurance.new
    respond_with(@insurance)
  end

  def edit
  end

  def create
    @insurance = Insurance.new(insurance_params)
    @insurance.save
    respond_with(@insurance)
  end

  def update
    @insurance.update(insurance_params)
    respond_with(@insurance)
  end

  def destroy
    @insurance.destroy
    respond_with(@insurance)
  end

  private
    def set_insurance
      @insurance = Insurance.find(params[:id])
    end

    def insurance_params
      params.require(:insurance).permit(:name)
    end
end

1 个答案:

答案 0 :(得分:1)

您似乎没有 var totseconds = 10; var seconds = totseconds; function floor(x) { return x | 0; } function pad(n) { if (n < 0) { n = -n; } if (n < 10) { return '0' + n.toString(); } return n.toString(); } function stopTimer() { clearTimeout(countdownTimer); if (seconds > 60) { var rs = seconds % 60; var m = seconds / 60; windows.alert((totalseconds / 60) - (m + 1) + " minutes and " + totalseconds - (rs + 1) + " seconds") } //else {window.alert((seconds +1)+ " seconds");} else { window.alert(totseconds - (seconds + 1) + " seconds"); } } function secondPassed() { var minutes = pad(floor(seconds / 60)); if (seconds < 0) { minutes = '-' + minutes; } var remainingSeconds = pad(seconds % 60); document.getElementById('countdown').innerHTML = minutes + ":" + remainingSeconds; if (seconds > 0) { seconds--; if (seconds > 8) { document.body.style.backgroundColor = "green"; } else if (seconds == 5) { document.body.style.backgroundColor = "yellow"; } } else { document.body.style.backgroundColor = "red"; if (seconds % 2 == 0) { document.getElementById('skull').style.display = "block"; } if (seconds % 2 != 0) { document.getElementById('skull').style.display = "none"; } seconds--; } } <img id="skull" src="http://s15.postimg.org/es5w3xpob/skull.gif" style="position:absolute; z-index: -1;display:none;"> <div style=" z-index:10;"> <p align="center"> <span id="countdown" style="color:black; font-size: 50px; font-weight: bold;"></span> </br> <button onclick="countdownTimer = setInterval('secondPassed()', 1000)">Start</button> <button onclick="stopTimer()">Stop</button> </p> </div> 在列入白名单的属性中(在insurance中)并且很可能您没有在数据库中定义此类字段(为什么您要定义与模型相同的属性名字?:)),

所以以下引发了一个错误:

insurance_params

你可能想要的是

      <%= f.label :insurance %><br>
      <%= f.text_field :insurance, class: "form-control" %>