Overriding the default views in RailsAdmin - ruby-on-rails

I am using Ruby on Rails 4.2.1 with RailsAdmin. The gem works excellent, but I have the requirement that the layout of the admin panel and the forms must look different than what is generated by default. For example, the navigation should be horizontal top, the forms should order the fields in two columns.
So far I haven't find a way to copy the views locally and modify them (like in Devise for example). I have tried to replicate the views manually in the respective path under my views folder by copying the original views, but I got problems with the helper methods that are part of RailsAdmin not being accessible from my views.
I dug deeper and found that there is a task copy_views, it was referred to in questions for the older versions of the gem, but if I try to use it now rake rails_admin:copy_views, it is not available anymore.
Am I doing something wrong, or is there another way to do this?

You can create folders in your app
app/views/rails_admin/main for https://github.com/sferik/rails_admin/tree/master/app/views/rails_admin/main
app/views/layouts/rails_admin/ for
https://github.com/sferik/rails_admin/tree/master/app/views/layouts/rails_admin
Put modified files there. It can get a little messy and you will need to update the files if the gem changes.

Related

Creating a gem for cells components

I want to create UI components to enable users to edit data present in a specified structure. I decided to give Cells a try, but I need to encapsulate the whole code in a gem, since I want to provide this components as an extension to an existing gem (criteria_operator), which is the source of the classes used for the data.
Is this possible? And if yes, how do I start? Normally, cells expects you to create views and models in specific folders of the default rails folder structure. When creating a gem, I only have the lib folder...
If you need any additional information, please just point it out in the comments. I wasn't sure if there is anything useful I could provide.
Disclaimer: The gem mentioned was created by me, and this question isn't intended to promote it.
To use another gem- criteria_operator, just add it to your gemspec:
s.add_runtime_dependency('gem_name', '~> <version>')
or add it to your gems's Gemfile.
To have models and views in your gem, you can use rails engine.
Rails engine allow you to wrap a specific Rails application or subset of it inside a gem.

changing complete layout in spree

I am working on spree 1.0.0 and have been doing some research on it
for my e-commerce site.
I have already made and used some existing extensions in my app. Now,
I am working on layouts and have been trying to figure out that what
are the best possible ways for that.
My need is that I have to change the complete front end layout of my
store in comparison of what spree provides.
Some of the options from my point of view are
-> Use an extension to write all the views that overrides the templates that spree provides,
-> Use Deface to override views (which would be hectic as I have to change approx everything on almost every page)
-> Use mixed functionality of the above options.
or is there another way to do this.
thanks in advance.
You are likely to have a new issue soon: to tell your new controller to use your new spree_application layout.
The spree google group indicates that you can use inheritance to use the main application everywhere: https://groups.google.com/forum/?fromgroups#!topic/spree-user/mB02WqMnCnw%5B1-25%5D
However, I still haven't figured out how to solve the routing for those controllers.
You can do this by overriding the app/views/layouts/spree_application.html.erb by placing an identically named file inside your application's app/views directory.

Change Rails Scaffold Naming Scheme

I'm a happy user of RoR but have one complaint. When I do script/generate scaffold it automatically generates all my files and places them in their proper folders. However, all the different scaffolds I've created name their view files the same.
I have a bunch of index.html.erb view files and when I have them open in my text editor, it's almost impossible to tell what controller they're related to.
I'd like to change the default naming scheme of the scaffold command to name the individual files to contain their view folder name. So, instead of index.html.erb, use index.home.html.
Is there a way to do this, or am I stuck? What solutions to the multiple files with the same name problem have you Rails developers discovered?
Thanks!
You're going to be fighting the Rails' conventions by going down that path and Rails works best when you work with it rather than against it. A core part of the philosophy of Rails is that there are a set of conventions that once learned make it easy to find your way around any Rails application.
Instead of trying to redefine how Rails works, I would recommend taking advantage of the features offered by your text editor or IDE for quickly navigating to the correct view template. For example, the Rails bundle within TextMate on the Mac lets you quickly open the view file associated with a particular model and there's a plugin for Vim that provides an equivalent feature.

Make Rails 2.3.5 aware of rails engine view path

According to the Ruby on Rails 2.3 Release Notes...
if your plugin has an app folder, then app/[models|controllers|helpers] will automatically be added to the Rails load path. Engines also support adding view paths now, and ActionMailer as well as Action View will use views from engines and other plugins.
There is supposed to be some way to make Rails aware of the app/views of your Rails engine, in 2.3. However, there is virtually no documentation on how this feature really works, that I can seem to find.
Can anyone help me get my view paths working from the context of a Rails Engine scenario?
IMPORTANT: The big issue is not with views as much as it is with partials. I need to be able to load partials from the view path of a rails engine.
Thanks!!
Turns out, I just needed to restart. This is done automatically by virtue of me defining a proper views directory within the nested app.
Durr!

Creating Plugins in rubyonrails

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.

Resources