Why does Ruby on Rails append an empty object when has_many and belongs_to are in use? -


Hey, I'm writing a website like 4chan. I have two models: board and pictures . A board has several images s:

  class board & lt; ActiveRecord :: Base # Relationships has_many: Picture, Dependent = & gt; : Delete the class and the picture & lt; ActiveRecord :: Base # Relationship related_to: board end   

I do this in my opinion boards / show.html.haml :

  - If @ board picture. someone? - @ Board.Picture% Article.picture- Article {: id = & gt; "Image - # {picture.id}"} - if picture.title? % Header% h2 = picture.title% img {: src = & gt; Picture.pic.url ,: alt = & gt; (Picture.title ?? Picture.title: 'untitled pic')} /% pre ~ picture.description - else meh This board is still empty   

and my good board controller In the :

  df show @ board = board.fund_b_short_name parameter [: id] expiration   

The problem is that always a For example, I have no board not picture s in the DB (this is with the picture) shown as image which is empty All ), but this output is:

  & lt ; Article class = 'image-text' id = 'image -' & gt; & Lt; Img alt = 'untitled photo' src = '/ pics / original / missing.png' & gt; & Lt; Pre & gt; & Lt; / Pre & gt; & Lt; / Article & gt;   

However, when I present it as a JSON, there is no image s with the output, as it should be: < / P>

  {"board": {"name": "n00bs", "created_at": "2011-03-16T17: 14: 32Z", "updated_at": "2011-03-16T17: 14: 32Z "," id ": 14," short_name ":" 0 "," picture ": []}}   

Before I do this, I can remove it and remove it from a every but the bug still remains and this super-duper is clumsy, how can it be? Why does @ board picture always empty an empty image object?

Try pictures. Instead. Any?

Comments