English 中文(简体)
如何将应用程序布局包装成 Ruby 宝石?
原标题:How to package application layout into a Ruby gem?

我正在研究一个由三个不同应用程序组成的项目。 他们应该共享一些模型和外部布局。 为了避免代码重复, 我试图将应用程序布局( project_ name/ app/views/layouts/ application.html. haml ) 提取成宝石 。

我遵循了这些步骤:

  1. create the base gem structure with bundle gem common
  2. place the layout file inside common/app/views/layouts/application.html.haml
  3. 写着Gemspec 描述符

    # -*- encoding: utf-8 -*-
    require File.expand_path( ../lib/common/version , __FILE__)
    
    Gem::Specification.new do |gem|
      gem.authors       = ["Arthur Alkmim"]
      gem.email         = ["myemail@here"]
      gem.description   = %q{Common project files}
      gem.summary       = %q{Common project files, including layout and migrations}
      gem.homepage      = ""
    
      gem.files         = `git ls-files`.split($)
      gem.executables   = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
      gem.test_files    = gem.files.grep(%r{^(test|spec|features)/})
      gem.name          = "common"
      gem.require_paths = ["lib"]
      gem.version       = Common::VERSION
    end
    
  4. 承诺修改

  5. gem build common.gemspec (successful)
  6. rake install (successful)
  7. Place gem common in the project Gemfile

但工程仍然无法加载应用程序布局。 我该怎么做才能告诉我的工程, 它必须通过宝石装入布局文件?

提前感谢。

最佳回答

我差不多解决了它。 我把 application.html.haml 改为 common.html.haml , 并将相关的布局调用在应用程序控制器中。 看来铁路公司不让我将应用程序.html 布局包装在宝石中, 但其他布局也行。 如果有人想出更好的解决方案( 工作上不太有效), 请张贴!

问题回答

你是否把你的宝石加进你的铁路宝石档案 以便把它包括在你的申请表里?

您可以使用路径选项指定开发中的相对路径,例如 。

gem  common , :path => "../path/to/gem"

不要忘了运行 bundle 安装





相关问题
rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

SSL slowness in EC2

We ve deployed our rails app to EC2. In our setup, we have two proxies on small instances behind round-robin DNS. These run nginx load balancers for a dynamically growing and shrinking farm of web ...

Auth-code with A-Za-z0-9 to use in an URL parameter

As part of a web application I need an auth-code to pass as a URL parameter. I am currently using (in Rails) : Digest::SHA1.hexdigest((object_id + rand(255)).to_s) Which provides long strings like : ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

activerecord has_many :through find with one sql call

I have a these 3 models: class User < ActiveRecord::Base has_many :permissions, :dependent => :destroy has_many :roles, :through => :permissions end class Permission < ActiveRecord::...

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

How to get SQL queries for each user where env is production

I’m developing an application dedicated to generate statistical reports, I would like that user after saving their stat report they save sql queries too. To do that I wrote the following module: ...

热门标签