我的问题是,如果我想测试编辑表单,我总是会得到这个异常..
你能帮我找出问题吗?
这是错误消息:
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