Making the logo interchangeable. Should I do it through the scss.erb or in the applications layout?

I am trying to make the logo of my rails app interchangeable, see previous post here

I have a Logo model which has the following fields name:string, image:string, default:boolean

I am using the carrierwave gem to upload an image to the image:string column. app/models/logo.rb

class Logo < ActiveRecord::Base
mount_uploader :image, LogoUploader
scope :default, where(default: true)

def falsify_all_others
  Logo.where('id != ?', self.id).each do |item|
    item.default = false
    item.save
    end
  end
end

I have a logos controller, seen here app/controllers/logos_controller.rb

class LogosController < ApplicationController
def new
  @logo= Logo.new
end

def create
  @logo = Logo.new(params[:logo])
  if @logo.save
    @logo.falsify_all_others
    redirect_to logos_path, :notice => "Logo has been uploaded successfully"
  else
  render "new"
  end
end

def edit
  @logo = Logo.find(params[:id]) 
end

def destroy
  @logo = Logo.find(params[:id])
  @logo.destroy
  flash[:notice] = "Logo has been obliterated!"
  redirect_to logos_path
end

def update
  @logo = Logo.find(params[:id])

  if @logo.update_attributes(params[:logo])
    @logo.falsify_all_others
    flash[:notice] = "Logo has been changed successfully!"
    redirect_to logos_path
  else 
    flash[:alert] = "Logo has not been updated."
    render :action => "edit"
  end
end

def show
  @logo = Logo.find(params[:id])
end

def index
  @logos = Logo.all
end 
end

and my applications controller

app/controllers/application_controller.rb

before_filter :get_logo

def get_logo
  @logo_default = Logo.default
end

So, once they have created/uploaded a few images through carrierwave, I display the logo like this: app/views/logos/show.html.erb

<%= image_tag @logo.image_url.to_s %>

I want to add the default logo (which I find through my logos scope) to display on the home page. Right now, it is done through the app/assets/stylesheets/styles.scss.erb through this code

section#header {
height: 220px;
position: relative;
h1 {
    background-image: url('<%= asset_path 'logo.png' %>');
    position: absolute;
    width: 412px;
    height: 188px;
    z-index: 999;
}

So my question is this: Do I need to pull the code that displays the logo out of the scss.erb and add to to the app/views/layouts/application.html.erb, or can I change it in the scss? like replace asset_path with an image_tag, or something like that? Let me know if you need more info/code i'll be happy to provide... Thanks in advance

Answers


I would recommend not to put it in the scss, because you'll likely want to precompile all this static stuff in production.


Need Your Help

Maven, Spring MVC: how to resolve AbstractAnnotationConfigDispatcherServletInitializer

spring maven spring-mvc

I have create Spring MVC project. I am try to use AbstractAnnotationConfigDispatcherServletInitializer as below.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.