Re: Newbie CMS question

That does make a lot more sense than the way I was trying!

Thanks very much, I’ll give it a bash and see how I get on. :slight_smile:

Henry

Henry B.: Music Production - Audio Engineering - Web D.

Hey Henry,
If your still there. I just wanted to say ‘that is only one way of
doing it’ one more time. To be honest its probably not the most common
way that I have seen in other projects but its my approach.

Probably a more common way would be to have an admin directory in your
controllers. So you would have a audio_items_controller and then you
would have an admin/audio_items_controller. That way you could really
easily go to www.yoursite/admin and you would be at your admin interface
and cruse around in there going to different controllers and just leave
the controllers outside of that directory to mostly do public display
stuff.

there is also more to that approach, but its pretty simple and how I
started out. It might be easier to deal with. And there are good
examples of that kind of structure being used all over. Check out just
about any OS rails app and look into the controller directory and you
will see an admin folder with repeating controllers that have been made
for editing and stuff in it, while the top level controllers do mostly
display stuff.

I got worried there because I didn’t want to give you the impression
that the way I described was what most of the rails apps are doing
today. Its the way I find most sensible and use in my own work. If I
had been less hypnotized by my own genius :wink: when I wrote my first
response I would have probably told you to make an admin module like I
mentioned above.

The best way to get some ideas is by looking at how other guys are doing
it. I would suggest looking around in mephisto or typo. You’ll learn
alot.

best wishes,
john

Thanks very much for your help! What you just described is the kind of
thing I was trying to do in the first place, but I couldn’t quite get my
head around doing it. I still have a few related issues with rails in
general that are throwing me a bit and would greatly appreciate your
advice if that’s ok?

In the example of my site, I make a model ‘web_item’ which also creates
a database ‘web_items’ and has the class name ‘WebItem’. Now at the
moment, I’m kind of thinking that I also have to make a controller
called ‘web_items’. What’s throwing me is the depot example in the AWD
book that just has the one main ‘Products’ database and a ‘products’
controller thats deals with that.

I guess what I’m trying to say is, can I have any number of controllers
dealing with a certain model? So in the example of my site again, can I
have a controller called ‘web’ which can get data from the ‘web_items’
model and display it using the ‘web’ view which would be what the public
sees. Then also like you suggested an admin controller folder containing
controllers which can access the same model but use different views and
actions and require authorisation to log in? And could I generate a
scaffold from each of these to help me get started?

Thanks
Henry

john wrote:

Hey Henry,
If your still there. I just wanted to say ‘that is only one way of
doing it’ one more time. To be honest its probably not the most common
way that I have seen in other projects but its my approach.

Probably a more common way would be to have an admin directory in your
controllers. So you would have a audio_items_controller and then you
would have an admin/audio_items_controller. That way you could really
easily go to www.yoursite/admin and you would be at your admin interface
and cruse around in there going to different controllers and just leave
the controllers outside of that directory to mostly do public display
stuff.

there is also more to that approach, but its pretty simple and how I
started out. It might be easier to deal with. And there are good
examples of that kind of structure being used all over. Check out just
about any OS rails app and look into the controller directory and you
will see an admin folder with repeating controllers that have been made
for editing and stuff in it, while the top level controllers do mostly
display stuff.

I got worried there because I didn’t want to give you the impression
that the way I described was what most of the rails apps are doing
today. Its the way I find most sensible and use in my own work. If I
had been less hypnotized by my own genius :wink: when I wrote my first
response I would have probably told you to make an admin module like I
mentioned above.

The best way to get some ideas is by looking at how other guys are doing
it. I would suggest looking around in mephisto or typo. You’ll learn
alot.

best wishes,
john

Henry B. wrote:

I guess what I’m trying to say is, can I have any number of controllers
dealing with a certain model? So in the example of my site again, can I
have a controller called ‘web’ which can get data from the ‘web_items’
model and display it using the ‘web’ view which would be what the public
sees. Then also like you suggested an admin controller folder containing
controllers which can access the same model but use different views and
actions and require authorisation to log in? And could I generate a
scaffold from each of these to help me get started?

Thanks
Henry

Thats exactly right. You can call your controllers whatever you want
and have as many as you want too. There is nothing that really binds a
controller to a model. It does tend to happen though, that you have
controllers and models with similar concepts in mind. So you usually do
have your WebItem model (whos job is to take care of its state and
provide class methods for finding WebItems in the DB and stuff) and then
a WebItemsController (who’s job is to control or direct or delegate the
flow of information between the WebItem models and the WebItem views
based on the request that comes in through the server). But this is
just a convenient pattern for organizing things. It just tends to keep
things clear. But it is in no way necessary. You can be as creative as
you would like.

To be honest if you really wanted to have a single admin_controller be
the one controller for all of your models it would work fine. There is
nothing stopping you from filling up a controller with every action
under the sun. So you could have made actions like edit_audio_item and
edit_web_item and basically crammed two scaffolding like sets of
methods into the same controller (each working on either web_items or
audio_items). Then in the future, any time you wanted to add a new
model that needed to be edited you could shoehorn another set of actions
in there. But this is clearly not a good way to keep things in good
order. But anyway yeah, controllers aren’t tightly bound to models like
they are to views or anything.

I hope that helps (or at least makes sense).

Spot on! Thanks very much! That’s defintely cleared things up for me.

I’ve just been having a play around, and everything seems to be coming
together now! I’ll defnintely be coming back here if I have any other
problems in the future.

Thanks again! :slight_smile:
Henry

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