rails-engines

Developing helper functions that generate HTML: should I rather use nested content_tag()s or partials?

爷,独闯天下 提交于 2019-12-10 21:25:37
问题 I'm at the start of developing a Rails engine (and gem) that should provide many small helper functions that generate HTML for views. Now I wonder whether it's advisable to rely on the use of many nested content_tag calls to generate the HTML, or if it's more pragmatic to just rely on partials. In my opinion, the first approach may be a bit cleaner (but slower in performance), but the 2nd approach seems much easier to do, so I guess I will favor the 2nd one. What do you guys think? 回答1: many

ActiveRecord relations between models on different engines

橙三吉。 提交于 2019-12-10 20:24:08
问题 I'm building a Rails app that is probably going to have a large amount of models. For now let's say that i need to have Users, and each User will have a personal Blog I've been developing the User-related part on a separate Engine (let's call it AuthEngine) that encapsulates the User model, authentication, etc. At the time this seemed like the best approach In parallel, my colleague was developing another engine, to deal with the blog features (let's call it BlogEngine). Now he needs to

Custom Views Scaffolding in Rails Engines

烂漫一生 提交于 2019-12-10 17:44:06
问题 I'm trying to get custom scaffolding working from my engine. I followed some tutorial on customizing Rails 3.2 scaffolding in a normal Rails App and put my customized templates in the engines /lib/templates/erb/scaffold directory but they don't get picked up by the app that includes the engine. Any suggestions? Update: I also tried to override the Rails ScaffoldGenerator's source_path and tried some other paths to put my template in, like: lib/rails/generators/erb/scaffold/templates 回答1: In

Rails can't find the module, if config.cache_classes = true

雨燕双飞 提交于 2019-12-10 17:14:39
问题 I have a gem which is mounted as engine in my rails app via routes.rb & Gemfile . Here are the important pieces: Apps' Gemfile source 'https://rubygems.org' gem 'rails', '3.2.9' gem 'mysql2' group :assets do gem 'sass-rails' gem 'coffee-rails' end gem 'jquery-rails' gem "common_client", path: "../common-client" App's routes.rb mount CommonClient::Engine => "", :as => 'shared' gem's routes.rb get '/register' => 'session#new_registration' gems's SessionController require 'common_client/session

`link_to` with parameters for an Engine route

无人久伴 提交于 2019-12-10 14:55:10
问题 (While this discusses Blacklight engine, I believe the question is actually purely about Rails.) Continuing my quest from scope around mount ineffective? (tl;dr: make the engine routes obey the same :locale scope as application routes), after digging through Rails source. Currently, I have this setup: # config/routes.rb Rails.application.routes.draw do Blacklight::Engine.routes.default_scope = { path: "(:locale)", locale: /en|ja/ } mount Blacklight::Engine => '/' scope "(:locale)", locale:

undefined local variable or method `main_app' on helper test

回眸只為那壹抹淺笑 提交于 2019-12-10 13:07:27
问题 I got error on rspec running my helper test on Rails Main Application (with further plugins) 1) MenuHelper maintence menu Failure/Error: before { menu = build_menu_maintence() } NameError: undefined local variable or method `main_app' for #<RSpec::Core::ExampleGroup::Nested_3::Nested_1:0x007f92f561f280> # ./app/helpers/menu_helper.rb:37:in `eval' # (eval):1:in `block in build_menu_items' # ./app/helpers/menu_helper.rb:37:in `eval' # ./app/helpers/menu_helper.rb:37:in `block in build_menu

How to auto-reload changes in a Rails Engine?

一个人想着一个人 提交于 2019-12-10 12:46:30
问题 I have a Rails 4.1.0 mountable engine. In the engine's application_helper.rb: module MyEngine module ApplicationHelper def test123 "test123" end end end The method is in the dummy app's view general/index.html.erb view: %<= test123 %> This works. However, when I change the string returned by def test123 and refresh the browser, the new string is not displayed. Of course, restarting the web server in the dummy app shows the new string. So the question is, how to reload the engine's files

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

故事扮演 提交于 2019-12-10 11:37:32
问题 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,

How to manage migrations for a rails engine + dummy app

丶灬走出姿态 提交于 2019-12-10 03:36:21
问题 I just joined a project developing a rails engine, that also has a dummy app for testing. foo/ foo/spec/dummy/ There are identical migrations in foo/db/migrate/ foo/spec/dummy/db/migrate/ If I rake db:migrate from the dummy app, all is well. If I do the same from the engine (current directory = foo) I get an error about multiple migrations with the same name. Q1) Are the Rakefiles borked? (should db:migrate recurse down to the dummy app?) Q2) Should the migrations only be in one directory? If

Rails Engines: Helpers only are reloaded when restarting the server

强颜欢笑 提交于 2019-12-10 01:31:50
问题 I'm currently experimenting with moving functionality into engines. It works nicely so far, but I'm a bit confused why certain parts of the engine are always automatically reloaded when something changed, and some are not. Specifically, when adding a helper method, I have to restart the Rails server, otherwise it is not seen by Rails. Is this normal behavior? Here's the relevant part of my engine: components/iq_list.rb # encoding: utf-8 require 'iq_list/engine' # Load IqList Modules module