SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Aug 2006
    0 Post(s)
    0 Thread(s)

    Rails: Need Help with starting up


    I just dove into Rails 2.0. I know the basics such as what MVC is and how to code in Ruby. I can't seem to get relationships working in rails though.

    My application has four models and controllers. They are:

    1. Jobs
    2. Machines
    3. Tasks
    4. Users

    The application just is a job logging site. The Use case would be like, you would see a screen with a menu with all the users, machines, and tasks (eg backup, defrag, virus scan). You would choose who the user is, what machine they worked on and what tasks were done on that machine and the date on which it was done.

    Example output would be:

    User | date | Machine | Task 1 | Task 2 | .... | Task N
    bob | mmyydd | machine1 | done | not done | .... | done

    I would like to add more users, machines and tasks in the future. My database is like this:

    Users Table
    user_id |username |password |firstname |lastname

    Machines Table
    machine_id | machine_name

    Tasks table
    task_id | task

    Jobs Table
    job_id | date | user_id | machine_id | task_id

    In the jobs Table, user_id, machine_id and task_id will point to the appropriate users, machines, tasks table rows.

    Now I did the first part and created Users, Machines and Task scaffold and I have populated the tables with the data. Now, how do I get the Jobs to work in order to put everything together?

    I would need to create Jobs/new, Jobs/index, and Jobs/edit actions. The Jobs/new action would have a form that would pull the information from Machines, Users, and Tasks and show them.

    So I went to job controller's index action and added:
        @jobs = Jobs.find(:all)
        @machines = Machine.find(:all)
        @users = User.find(:all)
        @tasks = Task.find(:all)
    in order to get the @ instance variables to get all the data from jobs, machines, users, tasks

    then I went to views and now I'm thinking I can create a form with this information that can submit to the database.

    Then I could just display this information.

    Am I basically on the right track?
    Last edited by garg; Apr 3, 2008 at 15:23.

  2. #2
    SitePoint Enthusiast AllTom's Avatar
    Join Date
    Feb 2008
    Wherever danger lies...
    0 Post(s)
    0 Thread(s)
    The code you pasted after "So I went to job controller's index action" is code that I would expect in the "new" action. If that's what you meant, then it looks like you're on the right track to me.
    There are some things you shouldn't try to code at home.

  3. #3
    SitePoint Enthusiast TomK32's Avatar
    Join Date
    Mar 2008
    Berchtesgaden, Germany
    0 Post(s)
    0 Thread(s)
    @garg: Better do your database in the migrations, makes it much easier and I guess it should be id instead of job_id and such.

    I'd suggest that you pick out a small open source app and read a bit into its source. You can find plenty at rubyforge and e.g. redmine is a very active one.

  4. #4
    SitePoint Member
    Join Date
    Oct 2007
    0 Post(s)
    0 Thread(s)
    Have a look at the Rapid RESTful Rails Apps article I wrote - it goes through the creation of a Rails project from start to end. It might point you in the right direction too.


Posting Permissions

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