0

我的问题是,如果我想测试编辑表单,我总是会得到这个异常..

你能帮我找出问题吗?

这是错误消息:

undefined method `model_name' for NilClass:Class
Extracted source (around line #5):

2: <div class="row">
3:         <div class="box">
4:                 <span id="logo">Azubiware 2.0</span><br><br>
5:                 <%= form_for(@bsinfo) do |f| %>
6:          <% @basedate = Date.new(@bsinfo.year) %>
7:          <% @basedate = @basedate.beginning_of_year %>
8:          <% @basedate = @basedate.beginning_of_week %>

我的用户表有相同的表格,并且可以正常工作...

class BsinfosController < ApplicationController

  def index
        @title = "Verwaltung Abwesehnheiten"
  end
 def new
        @title = "Sign up"
        @bsinfo = Bsinfo.new
  end

  def show
        @bsinfo = Bsinfo.find(params[:id])
        @title = @bsinfo.year
  end

  def create
        @bsinfo = Bsinfo.new(params[:bsinfo])
        if @bsinfo.save
                flash[:success] = "Schedule successfull created"
                redirect_to bsinfos_path
        else
                render 'new'
        end

  end

  def edit
        @title = "Settings"
  end

  def update
    if @bsinfo.update_attributes(params[:bsinfo])
      flash[:success] = "Profile successfull updated"
          redirect_to @bsinfo
    else
      render 'edit'
    end
  end

  def destroy
    Bsinfo.find(params[:id]).destroy
    flash[:success] = "Scheduel destroyed"
    redirect_to bsinfos_path
  end
end

编辑表单的链接就像

<% @bs = Bsinfo.all %>
<% @bs.each do |bsall| %>

<%= link_to "#{bsall.name}", edit_bsinfo_path(bsall), :class => "btn" %>

<% end %>

url 显示为 localhost:3000/bsinfos/17/edit

4

2 回答 2

0

The snippet of code:

form_for(@bsinfo)

is generating your error most likely because @bsinfo is nil.

I'd recommend looking at your controller code and checking for the conditions under which @bsinfo can be nil.

于 2012-07-10T02:04:54.823 回答
0

无论您的表单基于什么模型,都将返回为零。确保表单所基于的控制器中的 @var 实际上设置为您想要的对象的实例。

于 2012-07-09T22:51:26.880 回答