How to customize HTML structure in ActiveAdmin layout? - ruby-on-rails

I am trying to change the structure and design of the components of the ActiveAdmin layout, such as the navbar menu, icons and customize it to my style. Is this possible?
I need to overwrite the source code to be able to change the HTML structure, but I have tried to do it by placing files in the / lib folder and I have not succeeded. How could I overwrite the ActiveAdmin source code within my Rails project?

It is possible but many developers have discovered it is not easy. If you look through the various plugins you will find examples like Custom Layout, Sidebar, Menu and SubNav that may inspire you. However, if you are new to ActiveAdmin and your first priority is to customize the layout heavily then consider Administrate or vanilla Rails instead: they are still difficult, but you will be fighting the framework less.

Related

Editing UI of Samvera Hyrax

I wanted to customize the UI of Samvera Hyrax application and I've built a HTML template. Now, I want to replace the old UI with the content of my HTML files, when I say it on github I found view files where I can edit the application to implement my design. But after installing I could not find any files under views. Though I found application.html.erb.
I cannot figure out where <%= yeild %> has been pointing and when I replaced all the content with my home page code. It made no changes in the hyrax working.
Thanks in advance.
Assuming you followed the Hyrax installation procedure detailed on the github wiki here, what you'll notice looking at your routes in config/routes.rb is that Hyrax is mounted as a rails engine. So using the template you didn't clone Hyrax, but you created a new rails app that uses Hyrax as an Engine. If you haven't used Engines before, it may be worth reading up on them here. This is why you don't see all the views from the Hyrax project in the application you've generated using their template.
You can override views from the Engine by creating the view in your own project in the same path as it is in Hyrax. You may want to do some additional digging to determine if this is a path you really want to go down, as it can get complicated to maintain overridden views, and there may be alternative strategies that can accomplish some of what you want to do with CSS or themeing within Hyrax. It may depend on how much you want to override and how custom a theme you are trying to achieve.

Overriding the default views in RailsAdmin

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.

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.

Does every rails app have a default application.html.erb created in their layouts?

I just had a general doubt which I wanted to clear wrt Rails. I am currently working on Rails 2.0.2 for project specific purposes and I had a doubt especially related to this version of Rails.
I did a basic scaffold in my rails app on "posts".. something like ruby script/generate scaffold posts . This created a posts.html.erb file for me in my app/views/layouts .. I have seen in many blogs/screen casts they say when we add Javascript(JS) files like for e.g. those implementing jquery etc. we need to make include the necessary files in our "application.html.erb"files.. Now since I don't have anything exactly coined as such in my app.. does Rails by default take my posts.html.erb in my layouts as the equivalent application.html.erb..?
Or is that I need to explicitly create application.html.erb in my rails app?
My main concern behind this question is that would JS files be included in case if I have something like posts.html.erb or is that.. it should be done only in the application.html.erb..
Thank you..
For a PostsController, Rails will first look for an app/views/layouts/posts.html.erb file. Only if it doesn't find this controller-specific layout will it then fall back to app/views/layouts/application.html.erb.
does Rails by default take my posts.html.erb in my layouts as the equivalent application.html.erb..?
Yes. For the PostsController it will (by convention) take layouts/posts.html.erb as the overall layout template.
If you remove this file it will fall back to the layouts/application.html.erb layout.
My main concern behind this question is that would JS files be included in case if I have something like posts.html.erb or is that.. it should be done only in the application.html.erb..
You would have to include all necessary JS/CSS in each layout, as there is no layout inheritance.
If you want multiple layouts you can refactor out sections into partials (eg: for the <head> bit).
an app/views/layouts/application.html.erb file should have been generated for you when you did "rails new ProjectName"
make sure you have one... it controls the general layout of your web-site.

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