how to pass extra parameter to as_json from controller to model
<p>There are two apis in a controller. I need image for main_category and icon for nav-category. How can i pass xtra parameter from controller and can differentiate in model that this request is from main_category and this is from nav_category. Please help.</p>

<pre><code>def main_category
    category = Category.all
    render :json =&gt; :include =&gt; {:success=&gt; true,:data =&gt; category.as_json(@a,:only =&gt; [:name,:image_url])}

  end

  def nav_category
    category = Category.all
    render :json =&gt; {:success=&gt; true,:data =&gt; category.as_json(:only =&gt; [:name,:icon_url])}
  end
</code></pre>

<p>as_json in model is as :</p>

<pre><code>def as_json(options = { })
    if self.id == nil
    category = self.category
  elsif(@a=='main')
    h = super(options)
      h[:image_url]= "http://#{$request.try(:host_with_port)}#{self.image.url}"

      h
    else
      h = super(options)
      h[:image_url]= "http://#{$request.try(:host_with_port)}#{self.image.url}"
      h[:icon_url]= "http://#{$request.try(:host_with_port)}#{self.icon.url}"
      h
    end
end
</code></pre>