Topic: simple crud problem

Hi,

This is my first effort with RoR using the onlamp.com tutorial (http://www.onlamp.com/lpt/a/5546). I want to simply replace the example using my own table called "public".

My controller looks like:


class GlycanPublicController < ApplicationController
    scaffold :public
   
    def list
        @data = public.find_all
    end
   
   
end


and the views file list.rhtml:


<html>
<head>
<title>Listing ofdata</title>
</head>

<body>

<h1> List </h1>

<table border=1>
    <tr>
         <td><p align="center"><i><b>ID</b></i></td>
    <td><p align="center"><i><b>Name</b></i></td>

</tr>

<% @data.each do |public| %>
<tr>
  <td><%= public.id %></td>
  <td><%= public.name %></td>
   </tr>
<% end %>
</table>

<p><%= link_to "Create New Entry", :action => "new" %></p>

</body>
</html>



The error generated is:

undefined local variable or method `public' for #<PublicController:0x37f9dbc>

Re: simple crud problem

Try capitalizing public in the list action. Also, find_all is deprecated. Better to use find(:all).

def list
  @data = Public.find(:all)
end

Railscasts - Free Ruby on Rails Screencasts

Re: simple crud problem

Hi,

I now get an "uninitialized constant" for the public table

Re: simple crud problem

Have you created the Public model? What does that look like?

Also, did you give the table name the pluralized form? I guess it would be publics.

Railscasts - Free Ruby on Rails Screencasts