how ActiveAdmin works with existing controllers - ruby-on-rails-3

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.

Related

creating mobile version of rails app

I'm trying to work out how to redirect mobile users to other views in my rails app, but I'm missing something as it's not loading the mobile view from my device
in application_controller.rb, I added:
def check_for_mobile
session[:mobile_override] = params[:mobile] if params[:mobile]
prepare_for_mobile if mobile_device?
end
def prepare_for_mobile
prepend_view_path Rails.root + 'app' + 'views_mobile'
end
def mobile_device?
if session[:mobile_override]
session[:mobile_override] == "1"
else
# Season this regexp to taste. I prefer to treat iPad as non-mobile.
(request.user_agent =~ /(iPhone|iPod|Android|webOS|Mobile)/) && (request.user_agent !~ /iPad/)
end
end
helper_method :mobile_device?
then I have a file app/views/views_mobile/guidelines/index.html.erb
When I go to the index page on my iPhone it doesn't load the mobile index view - I'm not sure which part I'm missing...
Redirection for this kind of issue is a bad idea. Try responsive design. I would start with twitter bootstrap. This will give you a scaffold system to start with that will adjust to different screen sizes.
Also this is not uniquely a ruby on rails issue. This is a UI design issue.
Here's some good ideas.
Dont duplicate your views. it will just be harder to maintain down the road.
Use css media queries in your css to adjust your styles.
Try not to make two sites but one site that can bend and flex as it needs to.
All that being said I did not answer your specific question but instead tried to show you the way your going about it is wrong so I will understand if you dont mark this as correct.
Responsive resources.
http://twitter.github.io/bootstrap/
http://neat.bourbon.io/
http://www.abookapart.com/products/responsive-web-design
http://www.w3.org/TR/css3-mediaqueries/
Unless you left it out of your code snippet, I don't see where you're calling you're calling your check_for_mobile method. You probably need to add a before_filter to application.rb like:
before_filter :check_for_mobile
I also suggest you check out Ryan Bates Railscast on how to incorporate mobile-specific views into your Rails app. His strategy is similar to what you're trying to achieve, but instead of using a subfolder for your views he solves the same problem very elegantly by creating a 'mobile' MIME type. Check it out here:
http://railscasts.com/episodes/199-mobile-devices?view=asciicast

How to override inherited_resources with the rails scaffold command

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

What do I need to change im my App to migrate Restful_Authentication to Devise?

I found a tutorial here https://github.com/plataformatec/devise/wiki/How-To:-Migrate-from-restful_authentication-to-Devise-, however it seems like it is missing pieces of what to do, for example the restful_authentication plugin is still there...how do I remove it? Then how does Devise know what to get for my App...I've tried it but it just keeps breaking my App.
Erase everything in the user.rb controller (or your controller)
Make Sure all of Restful_Authenication is gone (there is quite a bit of includes that may be presnet)
Make sure devise_for :users is present in the routes.rb file
Look for method errors and replace them back in the User.rb controller.
Think that fixed it.

Devise authenticates before user/<id> but I want to turn it off

I've got Devise working on my Ruby on Rails application but viewing the user requires authentication and I don't want that. I've tried setting authenticate_user like so:
class UsersController < ApplicationController
before_filter :authenticate_user!, :except => [:show, :index]
..
end
But it still redirects to the sign_in page. Can anyone point me in the right direction?
Cheers,
Rim
PS: Please excuse my n00b-ness
Doh!
I was getting confused and had the wrong path. I been scratching my head for ages on that.
I fixed it...
I always use to copy controller files from devise gem folder to my applications controller folder
The devise controller files can be found here /usr/lib/ruby/gems/1.8/gems/devise-1.1.2/app/controllers/ (may be at different location in your case)
Copy devise folder in there and paste it to app/controllers/ and then customize registrations_controller as per your need
But I believe there must be some good solution on this. By the time you can use this.. :)

Rails3 UJS response not evaluated

It gives me the creeps,i'm done, i need some help here, i reverted multiple times back but i can't find the error.
Simple controller (customers),a simple form for adding a customer via :remote => true and the controller does respond_to do |format| { format.js } . Works fine, renders my create.js.rjs template.
I work for a few hours without making any javascript changes or changes to my controllers or authorization etc.. and when i try it again it's not working anymore.
What i mean with not working: Controller gets called, record saved, all partials rendered. But no javascript evaluated, not even a simple alert(1) at the beginning of the file.
I tried with different prototype.js versions and different rails.js versions, but nothing helped. I hope someone has a clue about this or already experienced this.
It's not that i don't want to post code. But it won't help. Its basic code that works and, after some changes where i don't know what i really changed (some locales here, some css there, html templates from a completely different controller a bit..)..
Currently developing with: ruby 1.9.2, rails 3.0.3, prototype 1.7 RC3, rails.js from github.
SOLVED
How stupid, I missed the part where the template naming changed. My application templace was named "application.rhtml". It worked until now. As it stopped to work, I changed it to "application.html.erb" and now it's working.