开发者

Why is my Rails instance variable nil in my view?

I am stuck on someothing probably incredibly stupid, but I can't find my problem. I'm using Rails 3.0.3, and ruby 1.9.2 on a ubuntu machine.

I am trying to just set an instance variable in m开发者_StackOverflow中文版y controller, and use it to create a form on a new view template, yet it is coming up nil in my view. I know that instance variables set in the controller are supposed to be copied to the view, but here its set to nil. Can anyone see what I'm doing wrong? Here is my error message:

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 %>

app/controllers/urls_controller.rb

class UrlsController < ApplicationController
  def new
    @url = Url.new
  end
end

app/views/urls/new.html.erb

<%= form_for @url do |f| %>
   <%= f.submit %>
<% end %>

app/models/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


Url is a reserved word I'm afraid.

http://wiki.rubyonrails.org/rails/pages/reservedwords

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜