can i "freeze the code" of activescaffold or rails_admin in rails? - ruby-on-rails

i want to generate a complex scaffold and then remove the gems
is there a way to freeze the code that rails_admin or activescaffold generates so i can edit it myself ? (similar to how rails scaffold does it)
is there another gem that generates a more complex scaffold?

In active scaffold to alter a scaffold's views you use overrides.

This depends on what version of Rails you're running. If >2.1, you can specify gems explicitly in environment.rb using config.gem, and then run rake gems:unpack to freeze those gems into the vendor/gems folder. For >=3.0 use the Builder tool to freeze the gem.
If <= 2.1, then you could do the above step manually -- copy all of the ActiveScaffold gem code into a folder in vendor/plugins, and remove the gem itself. See earlier plugin-based versions of ActiveScaffold for guidance.
You can also do this only as needed. To customize views, create an app/views/active_scaffold_overrides folder, and copy any ActiveScaffold partials to customize there. They will automatically be used across your app -- no need to duplicate them into each view. To customize controller actions, create a controller named ActiveScaffold, and then have all other scaffold controllers inherit from this new ActiveScaffoldController. Now you have somewhere to override the actions themselves, and you can override helpers in the generated ActiveScaffoldHelper file too.

Related

How to convert existing rails application to gem

I have a rails application that is kind of similar to the active_admin gem. I want to make this existing application into a gem.
I know that you can generate a gem with:
bundler gem gem_name_here
This command creates an empty gem. Which is fine I suppose, I just don't know where to put all my code.
You're ostensibly supposed to put all of your code in the /lib directory. However, my application has an assets pipeline and an app directory with all my models, controllers, and views. I don't know where to place all of these directories in the gem. Any thoughts or ideas?
If you need me to share any code, I'll gladly share it.
You're describing a rails engine. Engine is a miniature rails application that can be used inside other rails app. For more details see official rails guide

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.

How do I undo Rails template generation in Haml?

I installed a new gem to my Rails project - 'phrasing' - which has gem dependencies on multiple Haml gems. I need the gem (it is adding some phenomenal functionality to my project), and need the dependencies to be installed, but now when I run rails generate scaffold, all of the view templates are generated in Haml rather than ERB. I need views to continue to be generated in ERB.
I reviewed several previous StackOverflow articles, but most focus on converting TO Haml, and the answers around making sure that ERB is the default generator refer to removing lines from the config files, which are not there in my case (it appears that the gems are controlling the default layout format somehow).
(Note: While I appreciate that there may be several advantages to using Haml, and I might consider using it in a new project, I'd like to keep this one consistent, and it's already 80% finished in ERB.)
Turns out this was as simple as adding the following into class Application in the config/application.rb file:
config.generators do |g|
g.template_engine :erb
end
Still not sure why the manual override was necessary, but it is. This fixes it.

How to apply bootstrap to existing rails file generated through scaffold?

through railscasts, I found http://railscasts.com/episodes/328-twitter-bootstrap-basics that with the
gem 'less-rails' (this is the gem https://github.com/seyhunak/twitter-bootstrap-rails)
I can use
rails g bootstrap:themed scaffold-name -f
which applies bootstap to various classes like table, buttons etc. This is amazing timesaver but I am not able to find this for SASS as I am using SASS for my rails app (I am using this gem https://github.com/thomas-mcdonald/bootstrap-sass)
IS there any way to apply bootstap to existing scaffold code as me doing this manually can take lot of time ? OR is there any easy way to put the classes in the .erb files ?
Thanks

Divs instead of Tables in Rails generator

Is it possible to customize or find a gem that changes the behaviors of auto generating Tables in the views when I use rails scaffold and change it with Divs instead? Like cleaner templates, I'm using rayan's nifty generators but it uses tables instead of divs .
Any help would be highly appreciate .
Eqbal
I don't know of any such scaffold generator, but you can build one easily by taking Ryan's nifty generators as a starting point. You can modify it to your needs by following these steps:
Fork the repository on Github and clone it.
Change the file /rails_generators/nifty_scaffold/templates/views/erb/index.html.erb to fit your needs.
Commit and push your changes.
Add the newly created Gem to your Gemfile like this:
gem "nifty-generators", :gem => "https://github.com/[your_user]/nifty-generators.git"

Resources