Noobie controller model method difficulty

I am a real newbie at rails please help me. I have a controller called
groceries and a model also called groceries. I generated both the
model and controller with the /script.

I thought inside the controller i could call the model but it doesn’t
seem to work.

[
class GroceriesController < ApplicationController

def index
@groceries = groceries.find(:all)
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @groceries }
end
end

]

groceries.find(:all) gives undefined variable or method

Do i need to make a scaffold ? is there something more i need to do to
associate the model with the controller?

On Aug 10, 4:33 pm, tyliong [email protected] wrote:

    def index

Do i need to make a scaffold ? is there something more i need to do to
associate the model with the controller?

You don’t need to do anything to ‘associate’ a model with a controller
(because there isn’t really such an association).
The only think here is that your model is Grocery (or Groceries, but
should probably be the former) and so you need to do Grocery.find :all
(or Groceries.find :all)

Fred

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs