rails-engines

Creating a belongs_to relationship with a model from the main app from an engine model

让人想犯罪 __ 提交于 2019-12-10 00:08:39
问题 I've built myself a Rails Engine that requires that the main app have a Users table. I need to be able to create a relationship between one of the models in my engine and the Users table in the main app. Is this more complicated than just saying belongs_to :user ? I'm getting an error that says the User object is nil, but when I use the console it returns the right user. My assumption is that Rails assumed my belongs_to :user call meant a User's class in the same namespace as the engine, i.e.

Rails 3.0 Engine - Execute code in ActionController

不羁岁月 提交于 2019-12-09 04:27:43
问题 I am upgrading my Rails plugin to be an engine that works with the latest 3.0RC1 release and I'm having a bit of trouble figuring out the best (and most correct) way to extend ActionController . I've seen this post by DHH and this question here on SO, but my question is more about how to properly call code within the ActionController . For instance, I need to call the following within my engine's controller: class ApplicationController < ActionController::Base helper :all before_filter

How to extend a mountable engine's model inside another mountable engine with development environment reloading

旧巷老猫 提交于 2019-12-08 08:33:02
问题 Using Rails 3.2.2 and Ruby 1.9.2. I have a rails mountable engine EngineA that declares a User class inheriting form ActiveRecord::Base . I have another engine EngineB that wants to inject functionality into EngineA::User . Right now what I have done is shown below: Method 1: #EngineA app/models/engine_a/user.rb module EngineA class User < ActiveRecord::Base has_attached_file :avatar has_many :somethings end end #EngineB lib/engine_b/user.rb module EngineB module User def self.extended obj

Loading error for simple_form in rails 3.2.8 engine

邮差的信 提交于 2019-12-08 04:25:35
问题 When loading simple_form in our rails 3.2.8 engine, the simple_form initializer file simple_form.rb causes error: /config/initializers/simple_form.rb:2:in `<top (required)>': uninitialized constant SimpleForm (NameError) from c:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.2.8/lib/rails/engine.rb:588:in `block (2 levels) in <class:Engine>' from c:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.2.8/lib/rails/engine.rb:587:in `each' Under engine's config/initializers, the simple_form.rb is: # Use

Rails Engines with problems in Foreign keys

亡梦爱人 提交于 2019-12-07 12:38:40
问题 I'm developing a rails engine and this is my gem.gemspec s.required_ruby_version = '>= 2.0.0' s.add_dependency 'rails', '>= 4.2.0' s.add_dependency 'enumerate_it' s.add_dependency 'slim-rails' s.add_dependency 'bootstrap-sass' s.add_dependency 'jquery-rails' s.add_development_dependency 'rdoc' s.add_development_dependency 'tomdoc' s.add_development_dependency 'sqlite3' s.add_development_dependency 'rspec-rails' s.add_development_dependency 'timecop' s.add_development_dependency 'shoulda

How to extend a mountable engine's model inside another mountable engine with development environment reloading

吃可爱长大的小学妹 提交于 2019-12-07 08:41:19
Using Rails 3.2.2 and Ruby 1.9.2. I have a rails mountable engine EngineA that declares a User class inheriting form ActiveRecord::Base . I have another engine EngineB that wants to inject functionality into EngineA::User . Right now what I have done is shown below: Method 1: #EngineA app/models/engine_a/user.rb module EngineA class User < ActiveRecord::Base has_attached_file :avatar has_many :somethings end end #EngineB lib/engine_b/user.rb module EngineB module User def self.extended obj obj.class_eval do has_many :something_elses end end end end EngineA::User.extend EngineB::User This gives

Rails 4 Use Factory Girl factories from Engine

纵饮孤独 提交于 2019-12-07 06:27:22
问题 I've created a rails engine (full, not mountable) to provide models to a number of different rails apps. I use Factory Girl Rails to test this engine and the tests all run fine for the engine itself. I now want to be able to use these factories in other apps that include this engine. The dependencies for the Gemspec look like this: s.add_dependency "rails", "~> 4.0.3" s.add_dependency "mysql2", "~> 0.3.15" s.add_development_dependency "rspec-rails", "~> 3.0.0.beta" s.add_development

No Route Matches … Rails Engine

笑着哭i 提交于 2019-12-06 18:30:08
问题 So I keep getting the error: No route matches {:action=>"create", :controller=>"xaaron/api_keys"} Which is thrown in the test: it "should not create an api key for those not logged in" do post :create expect(response).to redirect_to xaaron.login_path end when I go to spec/dummy and run the rake routes command I see: api_keys GET /api_keys(.:format) xaaron/api_keys#index POST /api_keys(.:format) xaaron/api_keys#create new_api_key GET /api_keys/new(.:format) xaaron/api_keys#new edit_api_key GET

How to controller test rails 4 engine redirect back to main_app routes

喜你入骨 提交于 2019-12-06 14:57:11
I am having some trouble controller testing a rails engine that I created. The issue I am having is I can't seem to get rspec to use main_app routes. For instance, I am writing the following controller test. The test would pass if it wasn't for the main_app.root_path returning nil. The code I have in my controller spec is: context "successful session creation" do let(:user) {FactoryGirl.create :user} it 'sets user id session' do get :create, use_route: :authenticatable, email: user.email, password: 'password' expect(session[:user_id]).to eq user.id end end end In my controller I have: def

Rails.root from engine

萝らか妹 提交于 2019-12-06 00:26:43
问题 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? 回答1: 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