基于名称空间 Rails 3 覆盖公共文件夹
经过几个小时的搜索后,我在 Stack Overflow 上发布了我的第一个问题。
给出:我有以下route.rb:
resource: :non_namespaced_resource
namespace :namespaced_resource do # an example could be :admin
resources :one_nested_resource
resources :another_nested_resource
end
期望结果:是让命名空间资源使用自己的资产,非命名空间资源使用默认资产,如下所示:
# non-namespaced
/public
/public/images
/public/javascripts
/public/stylesheets
# namespaced
/admin
/admin/images
/admin/javascripts
/admin/stylesheets
我已经看到有关更改 config/environments/*.rb 或 config/application.rb 的信息并使用类似以下内容的信息,但找不到任何基于此的示例在命名空间上。
请记住,只有两个命名空间 ADMIN 和 PUBLIC。
config.action_controller.asset_path
config.action_controller.asset_dir
config.action_controller.javascripts_dir
config.action_controller.stylesheets_dir
config.action_controller.images_dir
问题:看来这应该是可能的。所以我的问题是,这可能吗?如果是这样,怎么办?提前致谢。
After searching for hours, I am posting my first question on Stack Overflow.
Given: I have the following route.rb:
resource: :non_namespaced_resource
namespace :namespaced_resource do # an example could be :admin
resources :one_nested_resource
resources :another_nested_resource
end
Desired Outcome: Is to have namespaced resources use its own assets and non-namespaced resources use the default assets, as shown below:
# non-namespaced
/public
/public/images
/public/javascripts
/public/stylesheets
# namespaced
/admin
/admin/images
/admin/javascripts
/admin/stylesheets
I have seen information on changing config/environments/*.rb
or config/application.rb
and use something like the following, but can not find any examples to do this based on the namespace.
Keep in mind there will ONLY be two namespaces ADMIN and PUBLIC.
config.action_controller.asset_path
config.action_controller.asset_dir
config.action_controller.javascripts_dir
config.action_controller.stylesheets_dir
config.action_controller.images_dir
Question: It seems this should be possible. So my question(s) is, is this possible? If so, how? Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这比我习惯的要困难一些,但我希望它能有所帮助。
第一步是识别一些仅针对您的
admin
命名空间运行的代码。我可能会创建另一个应用程序控制器,也许是admin_application_controller.rb
,它从您的基本应用程序控制器扩展,然后从该控制器扩展为您的所有管理控制器。例如。我很想知道这是否适合您,如果不适合,您会遇到什么问题以及您发现了什么,所以请告诉我们!祝你好运!!
[编辑]我更新了上面的代码以反映可用的成员:
This is going on a bit more of a limb than I'm used to, but I hope it helps.
The first step would be to identify some code that is run only for your
admin
namespace. I would probably create another application controller, perhapsadmin_application_controller.rb
, that extended from your base application controller, and then extend from that controller for all your admin controllers. For example.I'm quite interested to hear if this works for you, and if not, what problems you run into and what you find, so let us know! Good luck!!
[Edit] I've udpated the code above to reflect the members available: