[typo] hosting multiple blogs with the same app

hemant kumar inxs.hemant at gmail.com
Fri Oct 6 01:53:22 EDT 2006


ok..i get it.

I think content.rb is the one that is resetting the blog_ids just before the
actual save.
And I guess following call is the culprit:

class Content < ActiveRecord::Base
 def initialize(*args)
    super(*args)
    set_default_blog
  end

  def set_default_blog
    if self.blog_id == nil or self.blog_id == 0
      self.blog = Blog.default
    end
  end

end

Now...how do set some other values...there.

-----Original Message-----
From: hemant kumar [mailto:inxs.hemant at gmail.com] 
Sent: Friday, October 06, 2006 11:05 AM
To: 'typo-list at rubyforge.org'
Subject: hosting multiple blogs with the same app


Hi All,

I am modifying typo so as, I can host multiple blogs on the same typo.
And its almost done, except that...i am stuck at one place.

When a user posts a new article, depending upon current blog_id, I would
like to set the blog_id attribute of @article object.

So..in the admin/content_controller.rb:

We have:

def new_or_edit
    if request.post?
      set_article_author
      save_attachments
      logger.info("**** and blog id in article is #{@article.blog_id}")
      if @article.save
        set_article_categories
        set_the_flash
        redirect_to :action => 'show', :id => @article.id
      end
    end
end

So, just before the actual save, the value printed by logger.info is "****
and blog id in article is 2".But after @article.save is called...whatever
may be the current blog_id, the value that gets stored in database is always
1. And I have no clue, why is this.

Another pointer. new_or_edit calls a method "get_or_build_article", before
actually saving article:

when 'new'
                 art = this_blog.articles.build
                 logger.info("**** and blog id is #{this_blog.id}")
                 art.allow_comments = this_blog.default_allow_comments
                 art.allow_pings    = this_blog.default_allow_pings
                 art.published      = true
                 art


so...the above code also prints blog_id as 2. But again...the value that
goes in database is always 1.

Any clues, why is this?


gnufied




More information about the Typo-list mailing list