rails-engines

Making a custom plugin/gem/engine for Rails 3 app

别来无恙 提交于 2019-12-04 06:15:35
I am following the guide http://edgeguides.rubyonrails.org/plugins.html and it seems to be slightly outdated. Could you have a look on it and tell me which sections should be done in a different way in Rails 3? EDIT1: Links to alternative tutorials are also very welcome! You're right, that guide isn't the best (the last changelog entry is April 2010). Instead, I'd recommend you read: https://github.com/radar/guides/blob/master/gem-development.md I bumped into this question, and the answers are now outdated. The railsguide is currently up to date: http://guides.rubyonrails.org/engines.html The

Running spec for a rails engine from its parent app

百般思念 提交于 2019-12-04 06:13:58
I have rspec suite for parent app, and also some spec for engines attached. What I want is to run them with one command. Is there a way to include my gems paths into rspec load path? Or should I write rake task for this? I think this is an interesting question, but my opinion is that Rails Engines should be treated as an independent code base and therefore not tested in your parent app. The effect is that you'd treat a Rails Engine in your parent app much like you treat other gems (EG, devise, which is actually a Rails Engine). But let's say you have parent app functionality that relies on a

Helpers in Rails engine

房东的猫 提交于 2019-12-04 04:17:48
I am working on a rails engine and I have a problem with the helpers. Apparently this is a known "problem" but there's not a lot of solutions out there. The problem is that I have an AuthenticationHelper which I want to access globally - but it's not working. I've read that you could add a few lines to your init.rb but it does not seem to have any effect. Any idea what the best way to make an application available in an engine? EDIT: Fixed it- Just put the code (from the link) in the engine.rb instead. Put this code in engine.rb: config.to_prepare do ApplicationController.helper(MyEngineHelper

Rails.root from engine

谁说我不能喝 提交于 2019-12-04 04:11:03
I'm having some problem accessing Rails.root from my rails engine, that I'm creating. I need to fetch a yml config file from the main app. Is there any "best practices" for handling configurations for your engines? Let's assume you have a module attribute for that. # lib/my_engine.rb module MyEngine mattr_accessor :app_root end Then you can load it from the initialize block like so: # lib/my_engine/engine.rb module MyEngine class Engine < Rails::Engine initializer "my_engine.load_app_root" do |app| MyEngine.app_root = app.root end end end Instead use Rails.root use: MyEngine::Engine.root ;D 来源

How to access Rails Engines methods from main application?

谁都会走 提交于 2019-12-04 04:00:53
问题 I'm trying to use the current_order method defined in the Spree::Core engine: https://github.com/spree/spree/blob/master/core/lib/spree/core/current_order.rb In my view, I've tried Spree::Core::CurrentOrder.current_order Using just "current_order" in development works fine though, but not in production. So then I've tried to require it in my views file like this: require 'spree/core/current_order' I've also tried permutations of these other solutions: How to incorporate Rails Engine

Rails 4 Mountable Engine, couldn't find file 'jquery'

£可爱£侵袭症+ 提交于 2019-12-04 03:43:02
I'm creating a rails mountable engine plugin which uses the gem "jquery-rails". I added this code in .gemspec file s.add_dependency "jquery-rails", "~> 3.0.1" and run bundle install , bundle update . (BTW is this adding necessary? Since rails mountable engine already added "rails 4.0.1" which in turn required "jquery-rails 3.0.4" as its dependency from the start?). In app/assets/javascript/mountable_engine_name/application.js //= require jquery //= require jquery-ujs //= require_tree . But when I run the server on test/dummy/ and access any template which uses the tag <%= javascript_include

Ruby on Rails 3.1 Blog Engines

ぐ巨炮叔叔 提交于 2019-12-03 17:23:07
问题 I see a lot of people asking about Blog Engines, but most of the questions & answers are rather old. Or if they aren't old most of the projects are old. I'm wondering if anyone knows of any Blog Engines that currently support Rails 3.1 or are at least being actively developed to support Rails 3.1. I would also be interested in seeing any sample applications or blog posts written for Rails 3.1 Blogs. I am going to be adding a blog to one of my websites, and would prefer to simply use a Rails

rails 3.1.1 engines - with mountable engines, is it possible to access parent app assets, default layout?

北战南征 提交于 2019-12-03 14:53:18
This is more for experimentation - I am aware that I can do this with --full but I wanted the functionality of namespacing in the app to avoid conflicts The idea is to have a main app - which handles authentication, common items, admin screens etc Then creating engines to add further functionality like crm cms blog wiki forum etc These engines I can pick and choose as I need for whatever kind of app I am building. Is this possible? Is it just the case of applying both --mountable and --full options? Experimenting - would there be any issue if I use the full option add rspec and then simple add

Can a Rails 3 engine access models from it's parent application?

那年仲夏 提交于 2019-12-03 12:30:17
问题 I have a Rails Engine and I want to access the parents models. Is that possible? If so, how would I do it? 回答1: I didn't find any official documentation about it, but here's how you could still do it: tests = ::Test.all It'll return all tests from the parent app Test model. 来源: https://stackoverflow.com/questions/8855965/can-a-rails-3-engine-access-models-from-its-parent-application

What path is a mountable engine mounted on

别等时光非礼了梦想. 提交于 2019-12-03 09:41:04
问题 I need to know, from inside of a layout of a mountable engine, what path it's currently being mounted on. What would be the way to do it? E.g. my routes.rb contains the following line: mount BackendCore::Engine => "/backend" From inside of the BackendCore, I need the access to the value of "/backend". 回答1: If the engine is mouted :as => a different name, querying named_routes will not be sufficient. This monkey patch will do: class Rails::Engine def self.mounted_path route = Rails.application