title: Validate before Posting a text or an image
body: <p>I am working on a self-learning Rails application (the source code can be found <a href="http://github.com/stefioan/9FUN" rel="nofollow noreferrer">here</a>. I want to validate the presence of the content before posting a text or an image:</p>
  
  <p><img src="https://i.stack.imgur.com/2QP30.png" alt="here">.</p>
  
  <p>Those are my <a href="https://gist.github.com/stefioan/7723901" rel="nofollow noreferrer">models</a> or look below:</p>
  
  <pre><code>class Post &lt; ActiveRecord::Base
    belongs_to :user
    default_scope { order ("created_at DESC")}
    belongs_to :content, polymorphic: true
    has_reputation :votes, source: :user, aggregated_by: :sum
  end
  
  class PhotoPost &lt; ActiveRecord::Base
    has_attached_file :image, styles: {
      post: "200x200&gt;"
    }
  end
  
  class TextPost &lt; ActiveRecord::Base
    attr_accessible :body
  end
  </code></pre>
  
  <p>Here are my <a href="https://gist.github.com/stefioan/7723846" rel="nofollow noreferrer">controllers</a> in case they have a relation with this. Any other files can be found in my Github account. I am sure it will be messy to copy the whole project (that is why I am giving links for the controllers and for my project).</p>
  
  <p>So what I have tried so far. (I tried those on the Posts Model)</p>
  
  <p>=> Using validates_associated</p>
  
  <pre><code>validates_associated :content, :text_post
  </code></pre>
  
  <p>and getting an error "undefined method `text_post' for #Post:0x517c848>"</p>
  
  <p>=> Used validates</p>
  
  <pre><code>   validates :content, :presence =&gt; true
  </code></pre>
  
  <p>and getting no error however a post is created with no text.</p>
  
  <pre><code>validates :body, :presence =&gt; true
  </code></pre>
  
  <p>and getting an error "undefined method `body' for #Post:0x513e4a8>"</p>
  
  <p>If you need any other information please let me know and I will provide it asap.</p>
  
  <p>Thank you.</p>