Does every model need a corresponding Controller and View ?

or is there a way to intialize a model in another controller ?
Right now I’m getting

uninitialized constant CandidatesController:Canindustry

TIA
stuart

Dark Ambient wrote:

or is there a way to intialize a model in another controller ?
Right now I'm getting

uninitialized constant CandidatesController:Canindustry

The short answer is no. Just make sure Canindustry is correctly spelled.
Perhaps its CanIndustry if the model file name is can_industry.

Another option (some times required) is to add the following in the controller.

class FooController
  model 'can_industry' # or is it 'canindustry'
...
end

Long
www.edgesoft.ca

What Long said. Plus, it looks like your scope operator was mistyped.
Should be :: instead of :.

-- James

JDL wrote:

>
> Dark Ambient wrote:
> > or is there a way to intialize a model in another controller ?
> > Right now I'm getting
> >
> > uninitialized constant CandidatesController:Canindustry
> >
> The short answer is no. Just make sure Canindustry is correctly spelled.
> Perhaps its CanIndustry if the model file name is can_industry.
>
> Another option (some times required) is to add the following in the controller.
>
> class FooController
> model 'can_industry' # or is it 'canindustry'
> ...
> end
>

What Long said. Plus, it looks like your scope operator was mistyped.
Should be :: instead of :.

Good catch James!

Long

the model for clarification is -
class Canindustry < ActiveRecord::Base

with file name spelled canindustry.rb

Things seemed to be spelled correctly. I tried adding model ‘canindustry’
and was met with

undefined method `model’ for #CandidatesController:0x8481ba0

Not sure what’s going on .
Stuart


Hi Stuart,

Dark Ambient wrote:

is there a way to intialize a model in another controller ?

Just include the following line in your controller.

model :model_name

hth,
Bill

What are you trying to do? You shouldn't have to do anything special
to use a model in a controller. The models (by design) have no clue
about controllers at all. They aren't tied to any specific
controller, unless you've hacked something in that we don't know
about.

If you post the code that is actually breaking, we might be able to
help. Otherwise, it's just guessing.

-- James

Hey guys , it’s working now ! For whatever reason writing model ‘mymodel’ didn’t take and got an exception thrown.

model :mymodel though did the trick.

Very nice.Appreciate all the help.

Stuart