Hi all,
My application has a Article model that contains two collections:
sections and comments
Each section also has comments.
Each record is owned by the acting_user (although this might be
something that doesn't affect the case at all)
The layout flow is like this:
Article-show
- body
- comments
- new comment form
- section1
+ (new section-comment form)
- section2
+ (new section-comment form)
...
- new section form
When I show an article I want:
1: To show the textual body (article.body)
2: A list of all article.comments' bodies
3: An inline form for adding a new article.Comment.
4: A list of all article.sections' bodies
5: Each containing a comment [+] button to allow for a new
article.sections[i].Comment (click the plus and an inline form for the
comment should be shown)
6: An inline form for adding a new Article.Section
I have a few of these requirements in place, already. Req's 1, 4 and 6
are all ok with models and controllers as specified below. BTW: The
inline form for the sections is due to the Section controller
auto_actions_for :article, :create statement. In addition, viewing
sections without the article doesn't make sense, so the
auto_actions :all, :except => [:index, :show], hides the list and the
show-page.
The remaining problem is all in regards to the comments. First listing
them in the show-page for Article isn't automatic - as with the
sections. Secondly I cannot get the forms for new comments to display.
I have tried similar tricks as I applied to the SectionsController
with auto_actions and auto_actions_for but it seems that the
polymorphics behaviour makes that difficult. I have tried
auto_actions_for :commentator :create, as well as
auto_actions_for :article :create; auto_actions_for :section :create;
but none of those options work.
So, I then went over to create views/articles/show.dryml and modify
the usage of <show-page>. I got req #2 fixed easily, then went for req
#3.
The typical setup for an inline form (as with the sections for
article) is (using sq.brackets instead of angle-brackets since I have
no idea how google groups handles them):
[form with="&@section || new_for_current_user(@article.sections)"
owner="article" without-cancel param]
[submit: label="Add"/]
[/form]
I tried adding something similar in the show.dryml, like this:
[form with="&@comment || new_for_current_user(@article.comments)"
owner="article" without-cancel]
[submit: label="Add"/]
[/form]
But, this gives me an error:
"No reverse reflection for Comment.question"
This sounded like a hobo-problem, trying to figure out who is who in
the relationship so I tried to add "commentator" instead, as that is
the "link" in the relationship?
But that just gave me another error:
"You have a nil object when you didn't expect it!
The error occurred while evaluating nil.name"
I guess that this problem will repeat itself when I go for req #5, so
I haven't even tried that yet...
Any clues?
~Ronny
Here is my app's involved classes:
Models:
class Article < ActiveRecord::Base
hobo_model
fields do
body :text
timestamps
end
belongs_to :owner, :class_name => "User", :creator => true
has_many :sections
has_many :comments :as=> :commentator
class Section < ActiveRecord::Base
hobo_model
fields do
body :text
timestamps
end
belongs_to :article
belongs_to :owner, :class_name => "User", :creator => true
has_many :comments :as=> :commentator
class Comment < ActiveRecord::Base
hobo_model
fields do
body :text
timestamps
end
belongs_to :owner, :class_name => "User", :creator => true
belongs_to :commentator, :polymorphic => true
class User < ActiveRecord::Base
hobo_user_model
fields do
name :string, :unique
email_address :email_address, :unique, :login => true
administrator :boolean, :default => false
timestamps
end
has_many :articles, :class_name => "Article", :foreign_key =>
"owner_id"
has_many :sections, :class_name => "Section", :foreign_key =>
"owner_id"
has_many :comments, :class_name => "Comment", :foreign_key =>
"owner_id"
Controllers:
class ArticlesController < ApplicationController
hobo_model_controller
auto_actions :all
end
class SectionsController < ApplicationController
hobo_model_controller
auto_actions :all, :except => [:index, :show]
auto_actions_for :article, :create
end
class CommentsController < ApplicationController
hobo_model_controller
auto_actions :all, :except => [:index, :show]
end
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Hobo
Users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/hobousers?hl=en
-~----------~----~----~----~------~----~------~--~---