NoMethodError

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.

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

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.

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