简体   繁体   English

如何在Rails应用程序中重用模型和控制器

[英]How to re-use models and controllers across rails applications

We are coming up with a new twitter bootstrap theme for new functionality within our application. 我们正在为应用程序中的新功能提出一个新的twitter bootstrap主题。 Our existing functionality will use the existing theme with models/controllers . 我们现有的功能将使用现有主题和models/controllers

But I would like to re-use the existing models/controllers and use the new twitter bootstrap theme for the new functionality. 但我想重新使用现有的models/controllers并使用新的twitter bootstrap主题来实现新功能。

How do I go about addressing this and maintain the code bases (the old app will be on host:port1 and new app will be on host:port2) 我该如何解决此问题并维护代码库(旧应用将在host:port1上,新应用将在host:port2上)

Edit : 编辑:

My old rails application under public/javascripts public/stylesheets . 我在public/javascripts public/stylesheets下的旧Rails应用程序。 Some of the views are under app/views/foos/ Some of the views are under app/views/bars/ 一些视图位于app/views/foos/一些视图位于app/views/bars/

I would the new views under app/views/cars/ How should I reference my new index files to point to the new theme/css under app/assets 我将在app/views/cars/下找到新视图,如何引用新的索引文件以指向app/assets下的新theme/css

You can switch between css manifest files. 您可以在CSS清单文件之间切换。 So for new theme it could be like 所以对于新主题,它可能像

new_theme.css
 /*
 *= bootstrap_alternative_theme
   ... 
 */

old_theme.css
 /*
 *= bootstrap_original_theme
   ... 
 */   

And layouts/application.html.erb 和layouts / application.html.erb

<% if request.port == port1 %>
   <%= stylesheet_link_tag  "old_theme" %>
<% else %>
   <%= stylesheet_link_tag  "new_theme" %>
<% end %>

To add to benchwarmer answer, you might have the html and also the javascript modified so you can define a new layout and toggle between old and new layout as per your needs. 要增加替补答案,您可能需要修改html和javascript,以便定义新的布局 ,并根据需要在新旧布局之间切换。

But for compiling those assets, assuming your assets are not named application.css or application.js, add a line in your application.rb 但是对于编译这些资产,假设您的资产未命名为application.css或application.js,请在application.rb中添加一行

config.assets.precompile += %w(new.css new.js)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Rails重用:为什么控制器不能在局部中重用? - Rails re-use: why are controllers not reused within partials? 在轨道上重用视图 - re-use views on rails Clueless关于Rails ...请揭开如何在控制器视图和模型中使用变量的神秘面纱 - Clueless About Rails… Demystify how to use variables across controllers views and models please Rails:在 Rails 应用程序之间重用模型、控制器甚至视图 - Rails: Re-using models, controllers and even views between Rails applications Rails 5在具有不同字段的多个模型中重用before_validation代码 - Rails 5 re-use before_validation code in multiple models with different fields 如何跨各种控制器使用相同的变量-Rails上的ruby - How to use same variable across various controllers - ruby on rails 重构! 如何在数据库查询中重新使用变量以在 Rails 中检索数据 controller - Refactoring! How to Re-Use a Variable in Database Query to retrieve data in Rails controller 如何为不同的Rails应用程序使用具有不同迁移脚本的相同数据库 - How to re-use same database with different migration scripts for different rails apps Mini Test 和 Rails 6:在不同的测试中重用变量 - Mini Test and Rails 6: Re-use variables on different tests 在Rails 4应用程序中重用条件逻辑的最佳方法是什么? - What is the best way to re-use conditional logic in a Rails 4 app?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM