I have a model with one paperclip attachment :image
Model:
class HomeScreen < ActiveRecord::Base
before_create { !HomeScreen.has_record? }
validates :image, :attachment_presence => true
attr_accessible :image
has_attached_file :image
def self.has_record?
if HomeScreen.last
true
else
false
end
end
end
show method of my conttroller should return image with relative path but json should return absolute url with domain, how can I do that?
Controller:
class HomeScreenController < ApplicationController
# GET /home_screen
def show
@home_screen = HomeScreen.last
respond_to do |format|
format.html
format.json { render json: @home_screen }
end
end