1

Controllor:

  def new(user)
    @address = Address.new
    @address.user_id = user.id
  end

The link I click that triggers the error

<%= link_to "Add Address", new_address_path(current_user)%>

Address model

  belongs_to :user

User Model

  has_many :addresses

New Address View

<h1>New Address</h1>

<% form_for @address, :url => new_address_path do |f| %>
  <%= f.error_messages %>
  <%= render :partial => "form", :object => f %>
  <%= f.submit "Add Address" %>
<% end %>

Schema for Addresses

  create_table "addresses", :force => true do |t|
    t.string  "number"
    t.string  "street"
    t.string  "city"
    t.string  "state"
    t.string  "zip_code"
    t.integer "user_id"
  end

my routes

  map.resources :users
  map.resources :addresses

And the error is

uninitialized constant AddressesController
Parameters:

{"format"=>"#<user:0x105498c60>"}

2 Answers 2

1

In what controller is this method placed:

 def new(user)
    @address = Address.new
    @address.user_id = user.id
 end
Sign up to request clarification or add additional context in comments.

3 Comments

its in the address cornotreller
please make sure it is in the 'addresses' controller and not 'address' controller...
Glad to help you... :) I was able to quickly spot the problem since i'm just a Rails beginner and good with the basics.. :)
0

Instead of

new_address_path(current_user)

try using:

new_user_address_path(current_user)

and make sure current_user is a valid user object.

1 Comment

undefined method `new_user_address_path' for #<ActionView::Base:0x105070868>

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.