我有一个Rails 3应用程序,其中包含多个包含附加功能的引擎.每个引擎都是一个单独的服务,客户可以购买.
但是,我对来自引擎的路径存在问题,这些路由不容易用于控制器和视图.
控制器:
class ClassroomsController < ApplicationController
..
respond_to :html
def index
respond_with(@classrooms = @company.classrooms.all)
end
def new
respond_with(@classroom = @company.classrooms.build)
end
..
end
Run Code Online (Sandbox Code Playgroud)
app/views/classrooms/new.html.haml:
= form_for @classroom do |f|
..
f.submit
Run Code Online (Sandbox Code Playgroud)
config/routes.rb 在引擎中:
MyEngineName::Engine.routes.draw do
resources :classrooms
end
Run Code Online (Sandbox Code Playgroud)
config/routes.rb 在app中:
Seabed::Application.routes.draw do
mount MyEngineName::Engine => '/engine'
...
end
Run Code Online (Sandbox Code Playgroud)
lib/my_engine_name.rb 在引擎中:
module MyEngineName
class Engine < ::Rails::Engine
end
end
Run Code Online (Sandbox Code Playgroud)
试图进入/classrooms/new结果
NoMethodError in Classrooms#new
Showing app/views/classrooms/_form.html.haml where line #1 raised:
undefined method `hash_for_classrooms_path' for #<Module:0x00000104cff0f8>
Run Code Online (Sandbox Code Playgroud)
并尝试classrooms_path …
ruby-on-rails url-routing rails-routing rails-engines ruby-on-rails-3
之后gem update --system,当我做一些与rubygems相关的事情时,我会收到以下消息:
注意:不推荐使用Gem :: Specification#default_executable =.它将在2011-10-01之后删除.
Gem :: Specification#default_executable =从/usr/lib/ruby/gems/1.8/specifications/rubygems-update-1.7.2.gemspec:11调用.
我怎么能避免呢?我试图删除rubygems并重新安装,但这并没有解决它.
我目前有一个Rails 3.1应用程序,可以为多个不同的客户托管多个站点.每个站点都由一个模型表示,该模型知道域名和存储资产的路径,以及其他一些信息.
我一直app/sites/domain-name用作存储特定于某个站点的资产,视图和语言环境的位置,并且正在运行自定义中间件和控制器操作,用于修改Sprockets的加载路径,设置视图路径等等.
中间件(使用config.middleware.use "Configurator"in 加载application.rb):
class Configurator
def initialize(app)
@app = app
end
def call(env)
@env = env
clear_existing_paths
prepend_local_assets
@app.call(env)
end
def current_site
# find site using @env
end
def current_site_path
Rails.root.join('app', 'sites', current_site.path)
end
def clear_existing_paths
paths = Rails.application.assets.paths
Rails.application.assets.clear_paths
paths.each do |path|
next if path.include?("app/sites/")
Rails.application.assets.append_path path
end
end
def prepend_local_assets
path = current_site_path.join('assets')
return unless Dir.exists?(path)
['images', 'javascripts', 'misc', 'stylesheets'].each do |subdir|
asset_dir = path.join(subdir).to_s
next unless Dir.exists?(asset_dir)
next …Run Code Online (Sandbox Code Playgroud) 我试图在python 2.7中编写一个程序,它必须选择多个随机变量并将其打印出来.但是变量不能与之前打印的任何变量相同.
我一直在寻找谷歌和这个网站,我还没有找到任何字符串(我到目前为止只发现了整数).这是一个例子:
sentences = [a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p]
print (random.choice(sentences)) + (random.choice(sentences)) + (random.choice(sentences))
>>> a + b + a
Run Code Online (Sandbox Code Playgroud)
我不希望有重复,我希望它是这样的:
>>> a + b + c
Run Code Online (Sandbox Code Playgroud)
有什么办法可以实现吗?