0
我被困在可能令人难以置信的愚蠢,但我找不到我的问题。我在一台Ubuntu机器上使用Rails 3.0.3和ruby 1.9.2。为什么我的视图中的Rails实例变量为零?
我想在我的控制器中设置一个实例变量,并使用它在新视图模板上创建窗体,但它在我看来是零。我知道在控制器中设置的实例变量应该被复制到视图,但是在这里它的设置为零。任何人都可以看到我做错了什么?这是我的错误信息:
NoMethodError in Urls#new
undefined method `model_name' for NilClass:Class
Extracted source (around line #1):
1: <%= form_for @url do |f| %>
2: <%= f.submit %>
3: <% end %>
应用程序/控制器/ urls_controller.rb
class UrlsController < ApplicationController
def new
@url = Url.new
end
end
应用程序/视图/网址/ new.html.erb
<%= form_for @url do |f| %>
<%= f.submit %>
<% end %>
应用程序/模型/ URL .rb
# == Schema Information
# Schema version: 20110122002326
#
# Table name: urls
#
# id :integer not null, primary key
# long_url :text
# short_url :string(255)
# created_at :datetime
# updated_at :datetime
#
class Url < ActiveRecord::Base
end
app/controllers/application_controller.rb
class ApplicationController < ActionController::Base
protect_from_forgery
end
@!#$!谢谢..!要看看是否修复它 – noli 2011-01-22 19:40:34