Question

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 my 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
Was it helpful?

Solution

Url is a reserved word I'm afraid.

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top