SitePoint Sponsor

User Tag List

Results 1 to 9 of 9

Hybrid View

  1. #1
    Ribbit... Eric.Coleman's Avatar
    Join Date
    Jun 2001
    Location
    In your basement
    Posts
    1,268
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Writing admin / client applications

    I am attempting my first rails app now.. I got all the relationship down (wasn't that hard after looking at the docs)

    But, I have a question. How do you handle an app that should have 2 portions to it, an admin app, and a client app.

    I am assuming it would be 2 different rails apps that just work from the same database. Am I wrong to assume this?

    -- Eric
    Eric Coleman
    We're consentratin' on fallin' apart
    We were contenders, now throwin' the fight
    I just wanna believe, I just wanna believe in us

  2. #2
    SitePoint Addict
    Join Date
    Mar 2005
    Posts
    251
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Better to have an 'admin' controller within the same application.

  3. #3
    Ribbit... Eric.Coleman's Avatar
    Join Date
    Jun 2001
    Location
    In your basement
    Posts
    1,268
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    But, then, does everything have to bee off the admin controller? Or can I do something like admin/users/edit/1/

    ?
    Eric Coleman
    We're consentratin' on fallin' apart
    We were contenders, now throwin' the fight
    I just wanna believe, I just wanna believe in us

  4. #4
    grasshoppa Snowbird122's Avatar
    Join Date
    Apr 2001
    Location
    Austin
    Posts
    353
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In the DHH Agile development with Rails book, he builds a ecommerce app, including frontend and backend. He used a separate controller for each.
    http://www.echo-consulting.net - Sound Solutions for Online Inspriations.

  5. #5
    Ribbit... Eric.Coleman's Avatar
    Join Date
    Jun 2001
    Location
    In your basement
    Posts
    1,268
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Snowbird122
    In the DHH Agile development with Rails book, he builds a ecommerce app, including frontend and backend. He used a separate controller for each.
    So, the entire app would only have 2 controllers? If this isn't the case, can you provide me with an example as I don't have a copy of the book... yet.
    Eric Coleman
    We're consentratin' on fallin' apart
    We were contenders, now throwin' the fight
    I just wanna believe, I just wanna believe in us

  6. #6
    grasshoppa Snowbird122's Avatar
    Join Date
    Apr 2001
    Location
    Austin
    Posts
    353
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sure. You can get all the code here:
    http://www.pragmaticprogrammer.com/t...ails/code.html

    It is the Depot application (use the final version).

    For what it is worth, the book is very good.
    http://www.echo-consulting.net - Sound Solutions for Online Inspriations.

  7. #7
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by Eric.Coleman
    So, the entire app would only have 2 controllers? If this isn't the case, can you provide me with an example as I don't have a copy of the book... yet.
    You can subclass your controllers too, so you can for example have a Products controller in both the admin and client sections. For example, these two commands will create product controllers, one for public use and one for admins*:
    Code:
    ruby script/generate scaffold Admin::Product
    ruby script/generate controller Public::Product
    Your controllers would then be under /admin/products/ and /public/products/ respctively.

    Off Topic:

    * I created a controller on the public side instead of a scaffold because you don't need all the CRUD stuff exposed to the outside

  8. #8
    SitePoint Guru silver trophy Luke Redpath's Avatar
    Join Date
    Mar 2003
    Location
    London
    Posts
    794
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Eric.Coleman
    So, the entire app would only have 2 controllers? If this isn't the case, can you provide me with an example as I don't have a copy of the book... yet.
    No. Use as many controllers as you need but you will generally need more than two otherwise you would probably end up with massive controllers which is poor design. Controllers should be like any other class, with only as many methods as needed, and focussed on a particular subject.

    The best option is to take advantage of Rails' built-in routing for Ruby modules.

    Create a folder in your controller folder called "admin". Then, for all controllers inside this folder, make them part of an Admin module, so you might have a user controller for both the admin and front end:

    Code:
    # /controllers/user_controller.rb
    # http://mysite.com/user/
    
    class UserController < ActionController::Base
      # etc
    end
    
    # /controllers/admin/user_controller.rb
    # http://mysite.com/admin/
    
    class Admin::UserController < ActionController::Base
      # etc
    end
    In fact, the mapping of URLs to modules makes it very easy to break whole parts of your application up into individual modules and can be a good way of organising your controllers in general.

  9. #9
    SitePoint Guru silver trophy Luke Redpath's Avatar
    Join Date
    Mar 2003
    Location
    London
    Posts
    794
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh, and vinnie's command line above will generate the neccesary folders and files for you.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •