How to override inherited_resources with the rails scaffold command - ruby-on-rails-3

I am using the active_admin gem in my Rails 3 application, which has as a dependency inherited_resources. I am somewhat of a newb and would rather avoid the black box qualities of inherited_resources for my own controllers, however, when I run the default rails g scaffold command, the controllers that are generated are inheriting from inherited_resources. I know that I can manually override this by inheriting from ApplicationController, however, I would like to be able to generate the default rails scaffolds if possible.

-c=scaffold_controller
or add this to config/application.rb
config.generators do |g|
g.scaffold_controller "scaffold_controller"
end

Also noted in an issue thread over at github: https://github.com/josevalim/inherited_resources/issues/195

Related

Document upload (doc, docx, odt, etc.) and display in Rails (as text)?

Does anybody know how to upload a document to later show in a Rails application (as text)? Is Paperclip the right gem to do this? If it is how? (I have uploaded images before with Paperclip).
I like Paperclip. It seems well documented, and has worked well for everything I have needed. (I don't personally know any of them, but the clever folks at Thoughbot have created some pretty useful stuff, for which I feel indebted to them).
Obviously, you need to add Paperclip to your Gemfile, and (if you are using bundler) do your bundle install
Add to your model
has_attached_file :aFile
Add to you controller something to catch whatever you name it in your view (probably in your create and update methods)
#profile.aFile = params[:profile][:aFile]
Probably should check for its existence, if it is a required param
if params[:profile][:aFile].blank?
redirect_to #profile
else
render :action => 'do_something_interesting_with_file'
end
And that's about it. Don't forget your config entries. For example, if you are using some kind of post-processing on the file
Paperclip.options[:command_path] = "/opt/local/bin/"
I found this to be extraordinarily helpful
RailsCast by Ryan Bates

Rails 3.1 - changing default scaffold views and template

I'm using rails 3.1 with Zune Foundation templates and haml. I have tried to fiend ways to change the default scaffold view templates to use css I want so I get a consistent look with all scaffold without manually changing the view. I also use simple_form.
As I don't want to program my own generators, is there some easy and/or recommended ways to handle this?
Johann
You can override default view templates by creating your own templates in 'lib/templates/erb/scaffold' folder of your rails app.
lib/templates/erb/scaffold/_form.html.erb
lib/templates/erb/scaffold/edit.html.erb
lib/templates/erb/scaffold/index.html.erb
lib/templates/erb/scaffold/new.html.erb
lib/templates/erb/scaffold/show.html.erb
The default templates can be found here - https://github.com/rails/rails/tree/master/railties/lib/rails/generators/erb/scaffold/templates

how ActiveAdmin works with existing controllers

I'm finding it difficult to understand how ActiveAdmin(http://activeadmin.info/) works with existing controllers
I have the following controllers
app/controllers/projects_controller.rb
and I was successfully able to implement ActiveAdmin UI over my views in the above controller. But my question is I have added the following before_filter in my controller
class StaticContentsController < ApplicationController
before_filter :list_content_types
def index
#static_contents = StaticContent.all
end
end
But this filter seems to be not executing, in fact I changed the code inside the index method to
#static_contents = abc StaticContent.all
As it should give and error because of 'abc' section, but surprisingly my app works with out an error. My guess is 'ActiveAdmin' reads controllers my its own, not the existing ones
this is my index action path
http://localhost:3000/admin/static_contents
and this is in development mode
Can someone help me on understanding how controllers works with ActiveAdmin or am I missing something here
Following are my configs
rails (3.0.0)
ruby 1.8.7
activeadmin (0.3.2)
thanks in advance
sameera
Activeadmin controllers are not the same as your app's controllers, they are separate. The reason your code is not causing an exception from the activeadmin interface is because that code is never hit. The activeadmin controller documentation specifies how to modify the default activeadmin actions.

Devise generators use erb instead of haml

I'm trying to generate haml views with devise, but it always use erb instead. I'm running rails 3.1 & ruby 1.9.2. Rails generators (like scaffold) generates haml. I tried setting the template engine :
config.generators do |g|
g.template_engine :haml
end
But still doesn't work. If you have an idea, it is most welcomed.
Thanks for your time !
It's not possible to generate them out of the box. However, there is a short tutorial on how to convert the erb views from devise to haml layout using html2haml and a simple bash script.
That means that Devise doesn't have templates for HAML. However like #halfdan said it's pretty easy to convert with html2haml...

In Rails 3, using Formtastic 2, how can I replace the built in ordered list with div's?

In my Rails 3 application I'm using Twitter Bootstrap as a frame work for developing an in house project management system. I'm using Formtastic to help me with forms since it save a lot of time and code. My problem is getting the Formtastic code to output the forms in a way that correspond with Bootstrap's conventions. I've read a few items I found on Google suggesting that I should monkey patch Formtastic, but I haven't been able to do this successfully.
How can I customize Formtastic's output to use div's around each field so I can use Bootstrap with it?
Thank you for looking.
Well, today I tried forking formtastic and making it compatible with bootstrap... The markup is incredibly tightly coupled to the code, so I gave up and switched to simple_form instead. Works fine with the advice in Rails: Using simple_form and integrating Twitter Bootstrap
You can use the formtastic-bootstrap gem. You should be able to drop this in and it will generate HTML that will work naturally with Twitter Bootstrap.
If you use the SCSS files from the one of the scss-twitter-bootstrap projects, you can simply comment out or remove the include for the forms part of the CSS.
Simply copy them in to app/stylesheets (Rails 3.0) or app/assets/stylesheets and comment out:
// #import "forms.scss";
Don't forget to add the formtastic CSS back in:
<%= stylesheet_link_tag 'formtastic', 'formtastic_changes' %>