Stuart Hungerford
2005-Mar-20 01:54 UTC
Advice needed: implement hierarchy of directories site as Rails MVC?
Hi, Thanks to the replies on my earlier question about Rails applications that don''t feature a relational database, It seems Rails could be a good platform for my web project. What I need to do is present a website that (for now) shows the contents of a hierarchy of directories. The URLs to access the site will be: http://example.org/contents/<dir>/list http://example.org/contents/<dir>/<subdir>/list http://example.org/contents/<dir>/<subdir>/<subsubdir>/list Where <dir>, <subdir>, <subsubdir> etc are directory names. Each view of a directory would contain hyperlinks to the contents of the directory. The only action supported for now on a directory is "list", no edits, deletes, updates etc are allowed. As a complete Rails newbie, my initial thought was having one model per directory "level" with one controller per level would nicely reflect the structure of the hierarchy. The "contents" controller could somehow lookup a controller for the "<dir>" level, the "<dir>" level controller could somehow hand over control to the "<subdir>" controller and so on. But is this the most Rails oriented way to do this? Is it better to have one super "contents" controller that analyzes each whole URL and coordinates the model and view to use? I''m guessing I also need to avoid the scaffold scripts that assume use of ActiveRecord? Any advice on the most Rails-oriented way to do this much appreciated, Cheers, Stu
G''day Railers, I''ve only been looking at this for a couple of days, so please forgive me if this is a stupid question. I''m trying to build a small issue management system as a learning exercise in Rails, and I''m having troubly creating a new issue. My issue model looks like this: ---------------------------------------- class Issue < ActiveRecord::Base belongs_to :initiator, :foreign_key => "initiator" belongs_to :owner, :foreign_key => "owner" belongs_to :assignee, :foreign_key => "assigned_to" belongs_to :project belongs_to :subproject has_many :comments end ---------------------------------------- and my user & related types models look like this: ---------------------------------------- class User < ActiveRecord::Base has_many :comments, :foreign_key => ''submitter'' has_many :projects, :foreign_key => ''default_issue_owner'' has_many :subprojects, :foreign_key => ''default_issue_owner'' validates_uniqueness_of :email def full_name return first_name + " " + last_name end end class Initiator < User has_many :issues, :foreign_key => ''initiator'' end class Owner < User has_many :issues, :foreign_key => ''owner'' end class Assignee < User has_many :issues, :foreign_key => ''assignee'' end ---------------------------------------- In my issues controller, I''m getting a list of all the possible initiators, owners, and assignees to populate the form: ---------------------------------------- class IssuesController < ApplicationController scaffold :issue def new @projects = Project.find_all @subprojects = Subproject.find_all @initiators = Initiator.find_all @owners = Owner.find_all @assignees = Assignee.find_all end def list @issues = Issue.find_all end end ---------------------------------------- My new.rhtml view for issues then contains code to display these user lists as names: ---------------------------------------- <p> <label for="issue_initiator">Initiator</label> <br /> <%= collection_select("issue", "initiator" , @initiators, "id", "full_name") %> </p> ---------------------------------------- When I try to use this configuration to create a new issue, I get the following error: ---------------------------------------- ActiveRecord::AssociationTypeMismatch in Issues#create Initiator expected, got String ... Request *Parameters*: {:controller=>"issues", :action=>"create", :issue=>{"target_date(3i)"=>"19", "subproject_id"=>"1", "project_id"=>"1", "assigned_to"=>"1", "initiation_date(1i)"=>"2005", "initiator"=>"1", "initiation_date(2i)"=>"3", "description"=>"sfsf", "initiation_date(3i)"=>"19", "status_id"=>"", "owner"=>"1", "target_date(1i)"=>"2005", "target_date(2i)"=>"3"}} ---------------------------------------- Can anyone explain to me what I need to add to make Rails map the integer value it gets back from the form to the Initiator it represents? Thanks, Doug Gorley <douggorley-fVOoFLC7IWo@public.gmane.org>