No Method Error


#1

Hi,

I’m new to rails and have stumbled across this error. Where am I going
wrong?!

NoMethodError in Registeredphone#new

Showing app/views/registeredphone/new.rhtml where line #15 raised:

undefined method `user_id’ for #Registeredphone:0x3874030

Extracted source (around line #15):

12:
13: <% @user.each do |user| %>
14: <option value="<%= user.id %>"
15: <%= ‘selected’ if user.id == @registeredphone.user_id %>>
16: <%= user.txtForename %>
17:
18: <% end %>

My controller is as follows:

class RegisteredphoneController < ApplicationController
layout “standard-layout”
scaffold :registeredphone

def delete
	Registeredphone.find(@params['id']).destroy
	redirect_to :action => 'list'
end

def create
	@registeredphone = Registeredphone.new(@params['registeredphone'])
	@registeredphone.txtregisterdatetime = Time.now
	if @registeredphone.save
		redirect_to :action => 'list'
	else
		render_action 'new'
	end
end

def new
	@registeredphone = Registeredphone.new
	@user = User.find_all
end

def list
	@user = @params['user']
	@registeredphones = Registeredphone.find_all
end

def edit
	@registeredphone = Registeredphone.find(@params["id"])
	@user = User.find_all
end

end

Any help would be appreciated!!
Alana


#2

Alana Murphy wrote:

undefined method `user_id’ for #Registeredphone:0x3874030

My controller is as follows:

This error is telling you that your Registeredphone object doesn’t have
a user_id method which you attempt to use on line 15 of your view.

This could be because your registeredphones table doesn’t have a user_id
column, or because you didn’t define a user_id method in your
Registeredphone model.

Ray