Rails 5.1 Installing ActiveAdmin without Devise and a custom User model - ruby-on-rails

So I have a question, about using ActiveAdmin without Devise, the documentation is not clear on this for my needs and I see a lot of people not answering this question clearly. And to be clear, I am using Rails 5.1
To install without using devise you run
rails g active_admin:install --skip-users
In my case, I already have a User class and my own authentication. The docs say:
If you want to use an existing user class, provide it as an argument:
rails g active_admin:install User
this is where the confusion for me lies. Since, I already have a User class and DO NOT want to use Devise, and the generator above does install Devise, would I run
rails g active_admin:install User --skip-users
or
rails g active_admin:install --skip-users

The official documentation states:
After installing the gem, you need to run the generator. Here are your options:
If you don’t want to use Devise, run it with --skip-users:
rails g active_admin:install --skip-users
Further reading:
https://activeadmin.info/0-installation.html#setting-up-active-admin
After that create your own User model, as described in the docs. You can handle authentication as described here:
https://activeadmin.info/1-general-configuration.html#authentication
Normally it incorporates defining some controller method like authenticate_admin_user!.

Related

Ruby on Rails Devise - Setup - Already Used?

Working through the setup for Devise.
Running
rails generate devise admin
since admin seems to be the user model setup in my app where I now what it to be SSO auth but I get
The name 'Admin' is either already used in your application or reserved by Ruby on Rails. Please choose an alternative or use --skip-collision-check or --force to skip this check and run this generator again.
is it OK to force/ignore this? or ?

Migrate to Devise in Ruby on Rails

I have an existing model that uses bcrypt to encrypt the user password.
I wonder how I could migrate to use devise?
Do I still install devise the normal way and change the model attribute via database migration?
Add devise to your Gemfile, run bundle install, then rails generate devise ModelName (change ModelName to actual name of your model). This should add all needed things to your model as well as create a migration. I think devise will know, that your model already exists and it won't try to create new table, but it will modify existing one instead.
Then just run rake db:migrate, restart server and you should be good to go.
Just to be sure, use git or some other versioning system. It's been a while since I last tried this, so make sure you can easily go back, if something goes wrong.

Error regarding ActiveAdmin in Ruby on Rails when customizing the menu

Mac OS X 10.7.3 Lion,
Ruby 1.9.2,
Rails 3.2.2,
Sass 3.2.3
Following this tutorial:
http://activeadmin.info/documentation.html
Following this video tutorial
http://www.youtube.com/watch?v=tAxlrHcEg9U
I add the activeadmin gem, run bundle install, then run
rails generate active_admin:install
rails generate active_admin:resource POST
Only after creating the app/admin/posts.rb and trying to run either
db migrate
rails server
fails with the error
uninitialized constant Post NameError
with out that posts.rb file i am able to run the admin interface error free.
I tried moving the sass-rails gem out side of the :assets in my gem file and re-running bundle install as suggested in another question, but to no avail I still have the error
according to the getting started active admin tutorial "Post" is suppose to be a module name so i assume the code above is calling a class method (ActiveAdmin as the class, register as the method) and sending the module as a parameter and the block do end
Regardless the error is implying that RoR doesn't know what Post is. As if it does not exist. Being new to rails i do not know how to navigate well, meaning i do not even know where this ActiveAdmin source file is in order to dig through it for a method Post
Thank you for the consideration and your time, I appreciate it.
The linked tutorial assumes that you have already created a model named Post (and have run rake db:migrate to link it to the database). The purpose of the rails generate active_admin:resource Post command is to tell ActiveAdmin that you want it to consider the Post model in part of what it does.
Historically, you'll see models like Post and User in Rails a lot -- these are the commonly used examples of creating a blogging application (a user can create blog posts).
So, whatever models you have in your application can be registered with ActiveAdmin by replacing Post with the name of your model.
Another note: while generators like this tend to be forgiving, a Post is a model that is defined in post.rb and is linked to a SQL table called posts. Be careful with things like upper- and lower-case, and singular and plurals. In Rails they all fit together in a special way.

What is the equivalent of script/destroy scaffold User in Rails 3?

When I was using Rails 2, I did script/generate scaffold User to create the user model. Now I need to remove it, and I'm using Rails 3. I tried rails destroy scaffold User and rails destroy User, but these just created new rails projects named destroy. How do I do it? Thanks for reading.
Are you sure you are not running an older rails version at the time? Maybe forgot to switch to your Rails3 gemset with RVM?
It works fine here and this is the rails help output:
In addition to those, there are:
application Generate the Rails application code
destroy Undo code generated with "generate"

Any working tutorials for Authlogic?

I've been trying to build my first rails app and have gotten stuck on the issue of user authentication. I've found a number of tutorials for using various plug-ins to do this, but so far every single one of them is out-dated, and as a result, broken!
From what I've read, I think Authlogic may be the best fit for me, and I've tried two things:
1) Going through Railscast, episode #160 (which is a tutorial for setting it up)
2) Using Ryan B's nifty_authentication gem with the --authlogic tag
In both cases, I get the following error as soon as I try to do anything with a user:
undefined local variable or method `acts_as_authentic' for #
I believe this is from the User model:
class User < ActiveRecord::Base
acts_as_authentic
end
I'm sure I've installed the authlogic gem, and I've added
config.gem "authlogic"
to my environment.rb
Any ideas about what's wrong? Anybody know of a complete and up to date tutorial for adding user authentication?
Edit:
I'm running Ruby v. 1.8.6 and rails v. 2.3.5
There is one thing that Ryan Bates in the RailsCasts episode doesn't talk about is about creating sessions table in your database. Type rake db:sessions:create in the console and run the migration rake db:migrate. Also like ghoppe says run rake gems:install after installing the gem. That is a requisite.
Here's an example app with a step-by-step guide - it's from last year but should still be mostly if not entirely accurate:
authlogic_example
Since you added that line to your environment.rb, have you tried rake gems:install to ensure the gem is installed and working correctly?
Also, what version of Ruby? What version of Rails? Have you tried running gem environment and gem list to make sure they're installed and running from the right place?
Another option is to use authlogic as a plugin, with:
script/plugin install git://github.com/binarylogic/authlogic.git
It also helps to look at a projects that uses authlogic as authentication module, like the fat_free_crm project, have a look at user.rb there
Last but not least, there is an active mailing list:
authlogic mailing list
Becoming popular is also the devise gem. Here you can add authentication with script/generate devise and you will have some views for login as well.
I forked that authlogic_example and added activity_tracker, authlogic, paperclip for user profile images, declarative_authorization, and user to user messages.
http://github.com/jspooner/authlogic_cucumber_rspec_example

Resources