If you have a post and you do post.comments you get back an array, so you can't just do post.comments.body, otherwise you'd get undefined method 'body' for Array. What you'd do in Ruby is iterate through the array using each or some other iterator. In DRYML you'd do the same using <repeat>
<repeat:comments> inside here the context is a comment, so you can call view on fields of a comment, e.g. <view:body/> </repeat> On 22 Dec 2008, at 04:00, Ian Wood wrote: > > Hello all! > > As any of you that have read my previous posts will already know, I am > new to Hobo and my skill does not yet match my enthusiasm so please > bear with me! > > Whilst I am beginning to understand DRYML, Rapid, and Hobo in general, > one problem keeps manifesting itself over and over and despite my best > efforts I am no closer to cracking this particular nut. My problem is > context, I always seem to come unstuck on context. > > If I need to change tags, or call information from the implicit > context I have no problem. If I am working on a view for a "post" > model and I need to call a field in that model I get no trouble. But > if I need to call information from another model then I hit problems. > I understand that I need to change context momentarily from the > implicit context, but in practice I cannot make this work. > > Here's an example from my (very simple) Hobo Blog, which I am building > as a learning exercise for all things Hobo. > > I have created models and controllers for "posts" and "comments". No > prizes for guessing what I want these to do. > "post" contains two fields; "title" which is a string, and "body" > which is HTML. > "comment" contains only one field; "body" which is text. > > I put: belongs_to :post in the comment.rb model > I put: has_many :comments, :dependent => :destroy in the post.rb model > I put: auto_actions_for :post, [:new, :create] in > comments_controller.rb > I run my hobo_migration and all is well. > Now I want to customize the views a bit, before attempting to tackle > user permissions. > I already have an Index page that is displaying all of the posts I > have made. Initially it just displayed the "title" field of each post > as a link that would take me to the full post. It also has a counter > underneath telling me the number of comments. I want both the "title" > and "body" fields from "post" to display, plus the "body" field from > "comments". I will also want to display who made each comment, but as > I said I haven't got to user permissions yet! so, I define a custom > card tag for "post" in application.dryml. It looks like this: > > <def tag="card" for="Post"> > <card class="post" param="default" merge> > <header: param> > <h4 param="heading"><a><name/></a></h4> > <section param="content-body"> > <view:body param="description"/> > </section> > </header:> > <body: param ="content-body"> > <view:comments/> > </body:> > </card> > </def> > > The first part works great. Each post now displays it's "body" field > underneath the "title". > <view:comments/> is less successful. It only displays a numbered link > to any comments that might have been created for that post, not the > contents of the "body" field for "comments". I have tried setting the > context for this in loads of different ways, I either get an error, or > information other than that contained in "body" in "comments". > > If I do: > > <span class="view model:comment"> > <view:body/> > </span> > > I get a second copy of the "body" field from "post" not from "comment" > > If I do: > > <view:comments.body/> > > I get an undefined method `body' for #<Array:0x3b54214> error. > > I'm pretty sure that I am missing something very obvious here, but > this part of DRYML / Rapid is not clicking with me at all. I've read > and re-read the DRYML guide and the Rapid tag definitions, but I find > it quite hard to use either as Rapid is just a list of tags, and DRYML > forgoes using Rapid tags in it's examples. I had an earlier problem to > do with setting context, and it seems that all of my problems are > traceable back to this. What am I missing? > > Thanks guys, > > Ian > > > > > > > > > > > > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
