# NoMethodError

**URL:** <https://www.ruby-forum.com/t/nomethoderror/226012>\
**Category:** Rails\
**Created:** [June 26, 2008, 8:59pm UTC](https://www.ruby-forum.com/t/nomethoderror/226012 "2008-06-26T20:59:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![McLobster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/df788c/32.png) [@McLobster](https://www.ruby-forum.com/u/McLobster)\
**Post date:** [June 26, 2008, 8:59pm UTC](https://www.ruby-forum.com/t/nomethoderror/226012/1 "2008-06-26T20:59:05Z")

</div>

Hello there,

My task is to update an already existing website, an app created using  
Ruby on Rails. I’ve created a copy of the original database and  
modified it, adding some tables. I then set the new database as the  
database for the app and scaffolded the new tables. After tweaking a  
few files, and the RHTML code for the site, I get a NoMethodError:

undefined method `stb\_id’ for #RemoteSite:0x46b9f00

Extracted source (around line #332):

329: &nbsp  
330: \<% @stbs.each do |stb| %\>  
331: \<option value="\<%= stb.id %\>"  
332: \<%= ’ selected’ if stb.id == @remote\_site.stb\_id  
%\>\>  
333: \<%= stb.name %\>  
334:   
335: \<% end %\>

RAILS\_ROOT: C:/ruby/rails\_apps/alpha/config/…

Now you won’t find stb\_id anywhere in the controllers, models, or  
helpers. So the error should be a no brainer right? The “method”  
doesn’t exist. But here’s some of the original, working code:

```
<tr>
    <td class="category">VOD Platform:</td>
    <td class="option">
     <select name="remote_site[vodsystem_id]">
         <% @vodsystems.each do |vodsystem| %>
          <option value="<%= vodsystem.id %>"
            <%= ' selected' if vodsystem.id ==

```

@remote\_site.vodsystem\_id %\>\>  
\<%= vodsystem.fullname %\>  
  
\<% end %\>

Notice vodsystem\_id. This doesn’t exist either! As a matter of fact,  
I’ve copied the above code and replaced vodsystem with stb:

```
 <tr>
    <td class="category">STB Type:</td>
    <td class="option">
        <select name="remote_site[stb_id]">
        <option value="">&nbsp</option>
       <% @stbs.each do |stb| %>
      <option value="<%= stb.id %>"
              <%= ' selected' if stb.id == @remote_site.stb_id %>>
              <%= stb.name %>
          </option>
          <% end %>
      </select>
    </td>
  </tr>

```

And there are numerous blocks like this. For the life of me, I can’t  
find the list of (tablename)\_id methods so I can add my own for the  
tables I’ve created. I’ve done some queries in the database, and my  
tables are there, and they’re filled. Each table has an ‘id’ column  
and a ‘name’ column as well.

There are a few things I find odd with the app. First, all of the  
controller and helper ruby files only contain the class name, and end.  
There is only one controller file that has any code in it at all,  
which makes sense because it generates the website:

class RemoteSiteController \< ApplicationController  
scaffold :RemoteSite

def list

```
@remote_sites = RemoteSite.find(:all, :order => 'name asc, ip asc' )
@client = @params["client"]
@clients = Client.find(:all, :order => 'name asc')
@region = @params["region"]
@vodsystem = @params["vodsystem"]
@bmssystem = @params["bmssystem"]
@regions = Region.find_all
@quicklinks = Quicklink.find(:all, :order => 'name asc' )
@special_sites = SpecialSite.find(:all, :order => 'site_type asc,

```

client\_id asc’ )

end

def index  
redirect\_to(:action =\> “list”)  
end

def edit  
@users = User.find(:all, :order =\> ‘name asc’ )  
@remote\_site = RemoteSite.find(@params[“id”])  
@clients = Client.find\_all  
@vodsystems = Vodsystem.find(:all, :order =\> ‘name asc’ )  
@bmssystems = Bmssystem.find(:all, :order =\> ‘name asc’ )  
@oiversions = Oiversion.find\_all  
@oi\_statuses = OiStatus.find\_all  
@idgversions = Idgversion.find\_all  
@idg\_statuses = IdgStatus.find\_all  
@regions = Region.find\_all  
@models = Model.find\_all  
@rackmounts = Rackmount.find\_all  
@processors = Processor.find\_all  
@num\_processors = NumProcessor.find\_all  
@raid\_configs = RaidConfig.find\_all  
@operating\_systems = OperatingSystem.find\_all  
@application\_servers = ApplicationServer.find\_all  
@database\_servers = DatabaseServer.find\_all  
@jvm\_versions = JvmVersion.find\_all  
@license\_levels = LicenseLevel.find\_all  
@license\_types = LicenseType.find\_all  
@modifications = Modification.find(:all, :order =\> ‘timestamp  
desc’ )  
@current\_states = CurrentState.find\_all  
@stbs = Stb.find\_all

end

def new  
@clients = Client.find(:all, :order =\> ‘name asc’)  
@client = Client.find(@params[“client\_id”])  
@vodsystems = Vodsystem.find(:all, :order =\> ‘name asc’)  
@oiversions = Oiversion.find(:all, :order =\> ‘name desc’)  
@oi\_statuses = OiStatus.find(:all, :order =\> ‘name desc’)  
@idgversions = Idgversion.find(:all, :order =\> ‘name desc’)  
@idg\_statuses = IdgStatus.find(:all, :order =\> ‘name desc’)  
@regions = Region.find(:all, :order =\> ‘name asc’)  
@stbs = Stb.find(:all, :order =\> ‘name desc’)  
end

def update

```
 remote_site = RemoteSite.find(@params["id"])

 remote_site.attributes = @params["remote_site"]

 if ( remote_site.attributes["idgversion_id"] !=

```

remote\_site.attributes[“old\_idgversion”])  
new\_idg\_record = Modification.new  
new\_idg\_record.name = “IDG”  
new\_idg\_record.remote\_site\_id = remote\_site.attributes[“id”]  
new\_idg\_record.user\_id = remote\_site.attributes[“user\_id”]  
new\_idg\_record.from\_version =  
remote\_site.attributes[“old\_idgversion”]  
new\_idg\_record.to\_version =  
remote\_site.attributes[“idgversion\_id”]  
new\_idg\_record.timestamp = Time.now  
new\_idg\_record.save  
end

```
 if ( remote_site.attributes["oiversion_id"] !=

```

remote\_site.attributes[“old\_oiversion”])  
new\_oi\_record = Modification.new  
new\_oi\_record.name = “Oi”  
new\_oi\_record.remote\_site\_id = remote\_site.attributes[“id”]  
new\_oi\_record.user\_id = remote\_site.attributes[“user\_id”]  
new\_oi\_record.from\_version =  
remote\_site.attributes[“old\_oiversion”]  
new\_oi\_record.to\_version =  
remote\_site.attributes[“oiversion\_id”]  
new\_oi\_record.timestamp = Time.now  
new\_oi\_record.save  
end

```
   if remote_site.save
      redirect_to(:action => "list")
   else
      render_text "Couldn't add new item"
   end

```

end

def new\_link  
@clients = Client.find(:all, :order =\> ‘name asc’ )  
end

def delete  
RemoteSite.find(@params[‘id’]).destroy  
redirect\_to :action =\> ‘list’  
end  
end

Notice under the edit method I have added my tables, @oi\_statuses,  
@idg\_statuses, and @stbs.  
There are mentions of (table name)\_id here too.

One final peculiarity is the naming convention. Every table in the sql  
was named plurally. However, all the corresponding controller, helper,  
and model files are singular. When I scaffolded my tables, the  
corresponding controller, helper, and model files were still plurally  
named. Its a small oddity, but it’s been the cause of a few problems  
I’ve had already so its something I thought might be worth mentioning.

Any ideas on why the NoMethodError is popping up, or where to look to  
find these phantom methods would be greatly appreciated, thanks.

---

<div class="post-metadata">

**Author:** ![McLobster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/df788c/32.png) [@McLobster](https://www.ruby-forum.com/u/McLobster)\
**Post date:** [June 26, 2008, 9:07pm UTC](https://www.ruby-forum.com/t/nomethoderror/226012/2 "2008-06-26T21:07:17Z")

</div>

On 26 Jun 2008, at 19:58, McLobster wrote:

> and a ‘name’ column as well.

There is no list: rails creates accessor methods on the fly for all  
your database columns. Does your remote\_sites table have an stb\_id  
column?

> There are a few things I find odd with the app. First, all of the  
> controller and helper ruby files only contain the class name, and end.  
> There is only one controller file that has any code in it at all,  
> which makes sense because it generates the website:

hard to say from here, but if you have a controller that just displays  
static content then all you need are the view files, the controller  
doesn’t have to contain anything.

> was named plurally. However, all the corresponding controller, helper,  
> and model files are singular. When I scaffolded my tables, the

models are usually single, controllers plural. However if you ask  
rails to scaffold you the model foos instead of foo it will probably  
put plurals everywhere.

Fred

---

<div class="post-metadata">

**Author:** ![McLobster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/df788c/32.png) [@McLobster](https://www.ruby-forum.com/u/McLobster)\
**Post date:** [June 26, 2008, 9:12pm UTC](https://www.ruby-forum.com/t/nomethoderror/226012/3 "2008-06-26T21:12:34Z")

</div>

The remote\_sites table! That sneaky bastard. No, that table does not  
have a stb\_id column. I’ll add it in. Sadly, the table is gigantic.  
There are a lot of remote sites. So I’ll be adding in extra values for  
all the entries as well. Once I do though it sounds like it’ll work.  
Thanks again Fred. You’re amazing.

---

<div class="post-metadata">

**Author:** ![McLobster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/df788c/32.png) [@McLobster](https://www.ruby-forum.com/u/McLobster)\
**Post date:** [June 26, 2008, 9:10pm UTC](https://www.ruby-forum.com/t/nomethoderror/226012/4 "2008-06-26T21:10:13Z")

</div>

On 26 Jun 2008, at 19:58, McLobster wrote:

> ```
> <%= ' selected' if vodsystem.id ==
> 
> ```
> 
> @remote\_site.vodsystem\_id %\>\>  
> \<%= vodsystem.fullname %\>  
>   
> \<% end %\>  
>   
> PS, that simplifies to \<%= select ‘remote\_site’, ‘vod\_system\_id’,  
> @vod\_systems.collect {|v| [v.fullname, v.id]} %\>

Fred
