我看到很多人都在询问博客引擎,但大多数问题和答案都相当陈旧.或者,如果他们不老,大多数项目都是旧的.我想知道是否有人知道任何目前支持Rails 3.1的博客引擎,或者至少正在积极开发以支持Rails 3.1.
我也有兴趣看到为Rails 3.1博客编写的任何示例应用程序或博客文章.我将在我的一个网站上添加一个博客,并且如果有任何好的,我更愿意只使用Rails引擎或示例代码.我讨厌重新发明轮子.寻找简单的东西,而不是太固执,所以我可以轻松修改,以满足自己的需要.
我有一个Rails引擎,我想访问父母模型.那可能吗?如果是这样,我该怎么做?
我已经创建了一个Rails可安装应用程序并添加了'mongoid'和'rspec'gem.如果我现在尝试运行我的规格,我会收到以下错误:
Mongoid::Errors::NoSessionConfig:
Problem:
No configuration could be found for a session named 'default'.
Summary:
When attempting to create the new session, Mongoid could not find a session configuration for the name: 'default'. This is necessary in order to know the host, port, and options needed to connect.
Resolution:
Double check your mongoid.yml to make sure under the sessions key that a configuration exists for 'default'. If you have set the configuration programatically, ensure that 'default' exists in the configuration hash. …Run Code Online (Sandbox Code Playgroud) 我已经在 importmap-rails gem github 存储库中提出了一个关于此问题的问题,但我想我会在这里抛出这个问题,以防有人可能有解决方法
这是我迄今为止发现的
使用 Rails 7 alpha 2 或 Rails 7.0 生成的新引擎rails plugin new custom_page --mountable --full会生成一个新引擎,该引擎在捆绑的 gem 中包含 importmap-rails gem,但无法使用它。添加spec.add_dependency 'importmap-rails'到enginename.gemspec 没有什么区别,添加arequire importmap-rails到engine.rb 也没有区别。bin 目录中没有 importmap 可执行文件。调用bundle info importmap-rails
产生一个有希望的结果,表明默认情况下安装了 gem
* importmap-rails (0.8.1)
Summary: Use ESM with importmap to manage modern JavaScript in Rails without transpiling or bundling.
Homepage: https://github.com/rails/importmap-rails
Source Code: https://github.com/rails/importmap-rails
Path: /home/jamie/.rvm/gems/ruby-3.0.0@custom_page/gems/importmap-rails-0.8.1
Run Code Online (Sandbox Code Playgroud)
致电rails --tasks节目
rails app:importmap:install # Setup Importmap for the …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个动态界面.我的模型类存在的地方,我的控制器是在启动应用程序时动态创建的.
一切都发生在创建资源的路径文件中!
ActionController::Routing::Routes.draw do |map|
map.namespace :admin do |admin|
TestAdmin.models.each do |m|
admin.resources m.to_s.tableize.to_sym
end
end
end
Run Code Online (Sandbox Code Playgroud)
然后是我的BeAdmin类,它执行以下操作:
module TestAdmin
def self.included(base)
base.extend(ClassMethods)
end
module ClassMethods
def beadmin(options = {})
namespace_name = "Admin"
class_name = "#{self.to_s.pluralize.capitalize}Controller"
klass = namespace_name.constantize.const_set(class_name, Class.new(ApplicationController))
klass.module_eval do
def index
render :text => "test"
end
end
end
end
def self.models
all_models = []
Dir.chdir(File.join(Rails.root, "app/models")) do
Dir["**/*.rb"].each do |m|
class_name = m.sub(/\.rb$/,"").camelize
klass = class_name.split("::").inject(Object){ |klass,part| klass.const_get(part) }
all_models << "#{class_name}" if klass < ActiveRecord::Base && …Run Code Online (Sandbox Code Playgroud) 我正在使用Rails引擎的Ruby on Rails 3(.0)应用程序.但是,在我的本地应用程序中,我想覆盖Rails引擎提供的其中一个路由.
从引擎config/routes.rb:
match 'their_named_route' => 'controller#action', :as => 'the_route'
Run Code Online (Sandbox Code Playgroud)
从我的应用程序config/routes.rb:
match 'my_named_route' => 'controller#action', :as => 'the_route'
Run Code Online (Sandbox Code Playgroud)
但是,当我检查路线时,两者似乎都是活动的(并且它们的路线似乎"赢",至少在发动机控制器内)
$ rake routes
the_route /my_named_route(.:format) {:controller=>"controller", :action=>"action"}
the_route /their_named_route(.:format) {:controller=>"controller", :action=>"action"}
Run Code Online (Sandbox Code Playgroud)
有没有一种方法可以强制我的本地应用程序的命名路由优先?
我有一个Rails引擎,旨在为我们的大型项目提供一些模型和控制器.引擎的规格相当不错,在引擎的虚拟应用程序中使用了一堆模拟和一些全尺寸模型和控制器,以确保引擎正在做它应该做的事情并使用更大的应用程序.
但是,即使所有测试都通过,我也经常在更大的应用程序中更新引擎时发现损坏的行为.如果我的测试通过但是行为被破坏了,那么测试显然有些问题,但是什么呢?我嘲笑太多,还是不够?
为了让我更接近解决这个问题,我希望能够在整个应用程序中运行引擎的测试.这似乎应该是可能的,但我不完全了解rspec如何处理.
(这与这个问题有关但不完全相同;我不是试图从一个命令运行所有规范,只是为了在完整的应用程序环境中运行引擎的规范.这似乎也是相关的.实际上,我'我读过用rspec和rails-engines标记的每个问题- 这些问题并不多 - 而且它们都不是我需要的,或者没有答案.)
我有一个Rails 4.1.0可安装的引擎.在引擎的application_helper.rb中:
module MyEngine
module ApplicationHelper
def test123
"test123"
end
end
end
Run Code Online (Sandbox Code Playgroud)
该方法位于虚拟应用程序的general/index.html.erb视图中:
%<= test123 %>
Run Code Online (Sandbox Code Playgroud)
这有效.但是,当我更改返回的字符串def test123并刷新浏览器时,不会显示新字符串.
当然,在虚拟应用程序中重新启动Web服务器会显示新字符串.
所以问题是,如何在不重新启动Web服务器的情况下重新加载引擎的文件?
PS.我最好找一种方法来使用Rails本身,或者解决这个问题的特定宝石(但不是像Guard,Spork等通用宝石,尽管如果所有其他方法都失败了,我也会考虑这些.)
PPS.在SO上也有类似的问题,但我已经尝试过所有这些问题(即使它们适用于Rails 2.x,3.x),但它们并没有为我工作.
我有一个Rails引擎,我想从容器应用程序共享一个布局.我想支持主应用程序布局中的所有URL帮助程序,以使集成变得微不足道.这是为了支持容器应用程序中包含帮助程序的布局:
= link_to "Signup", new_user_path
= link_to "Login", new_user_path
...
Run Code Online (Sandbox Code Playgroud)
这导致:
未定义的局部变量或方法`new_user_path'用于#<#:0x007f9bf9a4a168>
我可以通过将application.html(在容器应用程序中)更改为:
= link_to "Signup", main_app.new_user_path
= link_to "Login", main_app.new_user_path
Run Code Online (Sandbox Code Playgroud)
但目标是使其集成引擎不需要用户对现有功能进行更改application.html.
我相信我也可以通过删除isolate_namespace Example来修复错误lib/example/engine.rb,但这几乎打破了引擎中的所有内容.
任何方式允许容器应用程序帮助程序和显式命名我的引擎帮助程序,以避免冲突?(即使用example.root_path而不是root_path)?
寻求将我的所有共享模型移动到可以包含在我的每个微应用程序中的引擎.
该引擎应为我们的所有遗留数据提供模型层,包括:
模型文件正在自动修补,没关系.
使用Nikolay Strum的db.rake对模式文件进行了修补:
namespace :db do
namespace :schema do
# desc 'Dump additional database schema'
task :dump => [:environment, :load_config] do
filename = "#{Rails.root}/db/foo_schema.rb"
File.open(filename, 'w:utf-8') do |file|
ActiveRecord::Base.establish_connection("foo_#{Rails.env}")
ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, file)
end
end
end
namespace :test do
# desc 'Purge and load foo_test schema'
task :load_schema do
# like db:test:purge
abcs = ActiveRecord::Base.configurations
ActiveRecord::Base.connection.recreate_database(abcs['foo_test']['database'], mysql_creation_options(abcs['foo_test']))
# like db:test:load_schema
ActiveRecord::Base.establish_connection('foo_test')
ActiveRecord::Schema.verbose = false
load("#{Rails.root}/db/foo_schema.rb")
end
end
end
Run Code Online (Sandbox Code Playgroud)
我们需要rake db:create和 …