rails-engines

Using an observer within an Engine

荒凉一梦 提交于 2019-12-02 06:16:09
I've created an Engine which is basically used for all of our projects. Now what I want to do is add a before_create callback to all of the models in this Engine. After some searching I found out that an observer is the way to go. So, I've created this observer: # app/models/baco/auth/auth_observer class Baco::Auth::AuthObserver < ActiveRecord::Observer def before_create( record ) p record end end And now I need to add it to the application, but of course in my Engine there is no such file as application.rb, so I've placed it in my engine: # lib/baco/auth/engine.rb require 'rails' require

How get Devise's current_user method in Rails Engine

…衆ロ難τιáo~ 提交于 2019-12-02 00:55:25
问题 I have a Rails application that's using the Devise gem, and I'm creating a Rails Engine to mount in this app. mount Comments::Engine => '/talk', :as => 'comments' Within the Engine, I want to get the current_user instance from main application. In {main_app}/initializers/comments.rb Comments.user_class = "User" Comments.current_user = "current_user" #current_user is Devise method(works fine in app) In {engine}/lib/comments.rb require "comments/engine" module Comments mattr_accessor :user

How to access Rails Engines methods from main application?

喜欢而已 提交于 2019-12-01 22:39:03
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 ApplicationController methods in a main app? A way to add before_filter from engine to application Rails 3.1:

How get Devise's current_user method in Rails Engine

拈花ヽ惹草 提交于 2019-12-01 21:33:01
I have a Rails application that's using the Devise gem, and I'm creating a Rails Engine to mount in this app. mount Comments::Engine => '/talk', :as => 'comments' Within the Engine, I want to get the current_user instance from main application. In {main_app}/initializers/comments.rb Comments.user_class = "User" Comments.current_user = "current_user" #current_user is Devise method(works fine in app) In {engine}/lib/comments.rb require "comments/engine" module Comments mattr_accessor :user_class, :current_user def self.user_class @@user_class.constantize end def self.current_user send(@@current

Rails Engine - File to import not found or unreadable: font-awesome

谁说胖子不能爱 提交于 2019-12-01 18:33:26
问题 I did a super simple rails app and used font-awesome with no problem. Expanding this to do the same steps in a rails engine produces the following error. File to import not found or unreadable: font-awesome I am unable to find a solution. If anyone has suggestions on how to make this simple rails engine work with font-awesome, I would be most appreciative. Steps to generate the rails engine and setup font-awesome... create the basic engine with one model class for testing rails plugin new

Rails Engine - File to import not found or unreadable: font-awesome

我的梦境 提交于 2019-12-01 17:58:07
I did a super simple rails app and used font-awesome with no problem. Expanding this to do the same steps in a rails engine produces the following error. File to import not found or unreadable: font-awesome I am unable to find a solution. If anyone has suggestions on how to make this simple rails engine work with font-awesome, I would be most appreciative. Steps to generate the rails engine and setup font-awesome... create the basic engine with one model class for testing rails plugin new testeng --full --mountable cd testeng bundle install rails g scaffold book title:string desc:string rake

How to use ActiveSupport::Configurable with Rails Engine

随声附和 提交于 2019-12-01 01:00:07
I want to give my rails engine gem a proper configuration possibilities. Something that looks like this in initializers/my_gem.rb (link to the current initializer) : MyGem.configure do |config| config.awesome_var = true # config.param_name = :page end So I've looked around for any clues in other gems and the best I cloud find was this kaminari/config.rb . But it looks so hacky that I think there must be a better way. The source file for ActiveSupport::Configurable got decent documentation: https://github.com/rails/rails/blob/master/activesupport/lib/active_support/configurable.rb I like to put

How to use ActiveSupport::Configurable with Rails Engine

天涯浪子 提交于 2019-11-30 19:30:01
问题 I want to give my rails engine gem a proper configuration possibilities. Something that looks like this in initializers/my_gem.rb (link to the current initializer): MyGem.configure do |config| config.awesome_var = true # config.param_name = :page end So I've looked around for any clues in other gems and the best I cloud find was this kaminari/config.rb. But it looks so hacky that I think there must be a better way. 回答1: The source file for ActiveSupport::Configurable got decent documentation:

Overriding named routes provided by Rails 3 Engines

橙三吉。 提交于 2019-11-30 18:44:20
I am working on a Ruby on Rails 3(.0) application that uses a Rails engine. However, in my local application, I want to override one of the routes provided by the Rails engine. From the engine config/routes.rb: match 'their_named_route' => 'controller#action', :as => 'the_route' From my application config/routes.rb: match 'my_named_route' => 'controller#action', :as => 'the_route' However, when I inspect the routes, both seem to be active (and their route appears to "win", at least within the engine controllers) $ rake routes the_route /my_named_route(.:format) {:controller=>"controller",

How to call a parent app's helper method from a rails 3.1 engine

假如想象 提交于 2019-11-30 16:39:40
I'm building a rails engine that uses the "acts as" format to establish relationships with the parent application's User model. module Cornerstone module ActsAsCornerstoneUser extend ActiveSupport::Concern module ClassMethods def acts_as_cornerstone_user(options = {}) #= Associations has_many :cornerstone_discussions #= Options Cornerstone::Config.auth_with << options[:auth_with] if options[:auth_with] Cornerstone::Config.auth_with.flatten! end end module InstanceMethods end end ActiveRecord::Base.send :include, ActsAsCornerstoneUser end I would like for a developer to be able to specify a