I have created an admin interface as a Rails engine. In the project I work in at the moment I need to add some custom javascript. I want to keep this in my main app and not add it in my engine.
Perhaps register some javascript or stylesheet files in a config file and let the engine include them.
Any ideas on how I can achieve this?
you are asking about ideas, so here is one: just use a convention!
it's common to do this in rails, so why not just do it for your engine. just document how to name the files and what to configure for that (assets need to be configured differently when they should not be included in application.js/css). the admin interface typus does the same thing: http://docs.typuscmf.com/customization/custom_css_and_js.html
in your engine, you can just check if that file is present in the mounting app and include it in that case.
should be pretty straight forward.
Related
When using Rails to only write an API, the term "app" seems less appropriate than something like "api". Is it possible to configure Rails to use a different folder besides "app" to load controllers, models, etc.? Preferably, I'd like my frontend code(outside the Rails asset pipeline) to live in "app", so creating a symlink isn't a preferable solution.
You can probably get it working by adding some hacks and fixes here and there. And then it will break again with the next gem/tool/IDE/plugin/...
Rails is strongly based on conventions, the app directory is one of them. Leaving as it is will save you lots of troubles.
I am trying to use Spree with my RoR application. Ok, I do follow all those guides and FAQs on official website when I want to customize something. That's ok and no problem with it. One question, to which I could not find a clue -- how is that possible, that there is nothing in apps/view, apps/models folders, but it's still working? I mean, yes, I can create something in these folders and redefine the behavior of my views (actually, this is one of the ways of customization), but I really want to understand the internals. I am pretty new to Rails and got used to classic app folder structure.
what you are wondering about is the magic of Rails Engines.
Ruby on Rails allows you to define Engines (your app is one too) and when it looks for views/controllers/etc.. all mounted engines are part of the search path.
So the view is inside the Spree gem, not visible to you - but it still looks in there.
If you put something in your view folder with the same name, it will take precedence over the views in the Rails engine you have in the Gem.
Here is a good guide on how Engines work in Rails:
http://edgeguides.rubyonrails.org/engines.html
One good example of these Engines is the jQuery-rails Gem you probably use inside your Application.
It has no code at all (except for some fallbacks for Rails 3.0 and below that don't have an asset pipeline), but the jQuery.js file in the app/assets/javascripts folder. And since the engine is in the load path you can require the asset that's in there..
The engine itself has the same folder structure as your app (app/views, app/controllers ...)
You can look at the internal structure of Spree here: https://github.com/spree/spree/tree/master/core/app
I have a Rails project that is basically a simple web app for a membership-based organization. We've open sourced the code on Github for the web app so that others can use it, but have a licensed design/layout that the original organization is going to use. This layout cannot be open sourced. I was wondering if others have run into the situation where you have an open-source Rails app with a non-OS design.
My initial thought is to put app/views in .gitignore, and to have anyone forking the code add their own views directory, perhaps including an app/views_default directory with a web-app-theme layout or something else to get people running. Is this the best option (realizing that there are other files such as JavaScript, CSS, etc that come with the layout that must also be ignored).
Does anyone have some good thoughts or pointers on this?
Hoopla - svn:externals for Git.
Instead of git:ignore, you can push the non-open-source stuff somewhere else, and your open-source code on github. Use hoopla to manage the externals.
http://6brand.com/git-svn-externals-rails-plugins.html
Rails Theme_Support plugin: http://github.com/aussiegeek/theme_support (There are forks as well). You can create a theme directory with multiple themes, and load the theme programmatically in ApplicationController. This would allow anyone to use the application, and simply supply their own theme in the themes directory, and would allow the project to have a "default" theme which would serve as an example.
I am using sfAdminJrollerTheme Plugin for some parts of my application, but when I generate new modules without admin generator, I lose same look and feel than jroller in my other application pages. I know maybe is good idea to use admin generator for everything but I cannot change all my modules.
Regards,
If you do not use the admin generator then you have to create your own look and feel using HTML and CSS.
Have a look at the generated files that exist in the cache folder to see the PHP that the admin generator generates.
The admin generator is excellent for making simple modules for manging data. Plus they can be built very quickly, but I would not advise using them for everything.
Creating a basic module and developing your own custom functionality is much more powerful.
I am creating a plugin which involves a controller, model & views. while i can move these files from the vendor/plugin directory to app/controllers, models & views respectively.
now i can run my controller & model just by copying them in lib folder of vendor/plugins/plugin_name/lib and they are directly accessible, but my views are not initialized from there, so i need a technique which can make my views in vendor/plugins/plugin_name/lib/views accessible to rails framework without copying.
i am trying to add them to actionview, but not sure how to do that.
please guide me on this.
There's ways you can add your plugin's views directory to the "search path" for ActionView, but the easiest way to handle all this is to just use something like the Rails Engines plugin to do all the hard work for you.
If you're looking to add models, views and controllers via a plugin, take a look at Desert: http://github.com/pivotal/desert. I'm not too keen on this approach, but Desert seems to work for people who like it.