0

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

1 Answer 1

3

Url is a reserved word I'm afraid.

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

Sign up to request clarification or add additional context in comments.

1 Comment

I changed the model and controller names to UrlRedirect, didn't work. I changed the @url instance variable to @rurl, and it did work. Thanks again

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.