I created a yml.erb file that will be used to configure some parts of my application. I would like to preload it with an initializer (I do not require it to change during application startup), the biggest problem is that this yml file contains a link to images that are inside the app / assets / images directory. I would like to use the image_path helper inside my yml.erb file, but I am having problems (I don’t know what I should include and where I should include it: if in the yml.erb file or in a file that parses the yml file. erb).
What I have at the moment
desktop_icons.rb (inside config / initializers)
require 'yaml' require 'rails' include ActionView::Helpers::AssetTagHelper module ManageFedertrekOrg class Application < Rails::Application def desktop_icons @icons ||= YAML.load(ERB.new(File.read("#{Rails.root}/config/icons.yml.erb")).result) end end end
icons.yml.erb (inside configuration)
- image: <%= image_path "rails" %> title: Test this title
home_controller.rb (internal controllers)
class HomeController < ApplicationController skip_filter :authenticate_user! def index @user_is_signed_in = user_signed_in? respond_to do |format| format.html { render :layout => false } # index.html.erb end end def icons result = { icons: MyApp::Application.desktop_icons, success: true, total: MyApp::Application.desktop_icons.count } respond_to do |format| format.json { render json: result } end end end
Any suggestion?
source share