Forum: Ruby on Rails No Method Error

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
434eecf2bd6df521bfd599e403be9996?d=identicon&s=25 Alana Murphy (alana)
on 2006-04-24 12:13
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:   <select name="registeredphone[user_id]">
13:    <% @user.each do |user| %>
14:        <option value="<%= user.id %>"
15:          <%= 'selected' if user.id == @registeredphone.user_id %>>
16:          <%= user.txtForename %>
17:        </option>
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
E28c35323f624b8b9ed8712e25105454?d=identicon&s=25 Ray Baxter (Guest)
on 2006-04-25 01:04
(Received via mailing list)
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
This topic is locked and can not be replied to.