heartcombo / devise

Flexible authentication solution for Rails with Warden.
http://blog.plataformatec.com.br/tag/devise/
MIT License
24k stars 5.55k forks source link

Use the new attributes API in Rails 5 #3880

Closed seanlinsley closed 8 years ago

seanlinsley commented 8 years ago

In order for other gems (like Formtastic) to properly tell that the virtual password attribute is a string type, in Rails 5 Devise will need to use the new attributes API.

This is what currently happens:

>> User.type_for_attribute('id').type
 => :integer
>> User.type_for_attribute('password').type
 => nil 

But once Devise is hooked up with the new API, type_for_attribute would return :string for the virtual password attribute.

seanlinsley commented 8 years ago

https://nvisium.com/blog/2015/06/22/using-rails-5-attributes-api-today-in/

seanlinsley commented 8 years ago

Here's a stack trace for the error when being used with Formtastic: https://github.com/activeadmin/activeadmin/pull/4254#issuecomment-168422718

lucasmazza commented 8 years ago

Sounds interesting, but I believe it's better to wait until we drop support for Rails 4.1/4.2 to use the new API, otherwise we will have to juggle with supporting multiple Rails APIs and Mongoid (which might not supply the same API for defining these attributes).

seanlinsley commented 8 years ago

Is there a plan for when Rails 4 will be dropped, and alternatively when Rails 5 will be supported? Is there anything myself or others can do to help with that process?

lucasmazza commented 8 years ago

@seanlinsley Devise 4 should keep compatibility with Rails 4.1, 4.2 and 5.0, but we currently don't have any plans for when to go Rails 5+ only.

seanlinsley commented 8 years ago

Is the plan to support Rails 5 without dropping Rails 4 support, thus delaying usage of the new attributes API?

lucasmazza commented 8 years ago

@seanlinsley yes.

arogachev commented 8 years ago

Initially I described problem here https://github.com/activeadmin/activeadmin/issues/4280 and thought that it was Active Admin problem. Then I thought it was Formtastic problem and posted issue here https://github.com/justinfrench/formtastic/issues/1187, but @mikz prompted that it's possibly Devise problem.

I'm using Rails 5.0.0.beta1, My Gemfile contents:

gem 'activeadmin', github: 'activeadmin/activeadmin', branch: 'rails-5-rspec'

I tried to update to latest commit of Formtastic on master branch, that didn't help:

gem 'formtastic', github: 'justinfrench/formtastic', branch: 'master'

Devise is added like so:

# Authentication
# Master branch is added for Rails 5 support
# https://github.com/plataformatec/devise/pull/3714
gem 'devise', github: 'plataformatec/devise', branch: 'master'

For example, this line from this file:

f.input :password, label: t('active_admin.devise.password.title')

generates the following HTML:

<input type="text" name="user[password]" id="user_password" maxlength="72">

So there is no type="password".

Is there any way to fix that except overriding these Active Admin forms and explicitly specifying type password?

lucasmazza commented 8 years ago

@arogachev can you set up a sample app with Devise + Rails 5 + Formtastic that replicates this issue so I can take a look? We might be able to come up with a different fix than using the new API.

lucasmazza commented 8 years ago

@arogachev I couldn't replicate this issue in a fresh app (https://github.com/lucasmazza/devise-formtastic-rails-5) so I'm still now sure of what might be happening wrong here.

arogachev commented 8 years ago

@lucasmazza Sorry, I didn't have enough time last days. I'll try either update gems or setup an app.

arogachev commented 8 years ago

@lucasmazza I updated both devise and formtastic gems to the latest condition using bundle update command (suffixed with gem name).

But then when I tried to start Puma (dev web server), I got this error:

/usr/local/rvm/gems/ruby-2.2.2@my_site/bundler/gems/activeadmin-599025964c95/lib/
active_admin/dependency.rb:79:in `match!': You provided devise 4.0.0.rc1 but we
need: ~> 3.2. (ActiveAdmin::DependencyError)
        from /usr/local/rvm/gems/ruby-2.2.2@my_site/bundler/gems/activeadmin-5990
25964c95/lib/active_admin/dependency.rb:48:in `method_missing'

Here is the Gemfile contents:

# Backend
gem 'activeadmin', github: 'activeadmin/activeadmin', branch: 'rails-5-rspec'

# Authentication
# Master branch is added for Rails 5 support
# https://github.com/plataformatec/devise/pull/3714
gem 'devise', github: 'plataformatec/devise', branch: 'master'

# FormBuilder DSL
gem 'formtastic', github: 'justinfrench/formtastic', branch: 'master'

Active Admin section in Gemfile.lock looks like this:

GIT
  remote: git://github.com/activeadmin/activeadmin.git
  revision: 599025964c95d1caaad012c34bd5fb4074729152
  branch: rails-5-rspec
  specs:
    activeadmin (1.0.0.pre2)
      arbre (~> 1.0, >= 1.0.2)
      bourbon
      coffee-rails
      formtastic (~> 3.1)
      formtastic_i18n
      inherited_resources (~> 1.6)
      jquery-rails
      jquery-ui-rails
      kaminari (~> 0.15)
      rails (>= 3.2, < 5.0)
      ransack (~> 1.3)
      sass-rails
arogachev commented 8 years ago

Seems like rails-5-spec branch of Active Admin was not updated since the moment of my last update.

arogachev commented 8 years ago

Is there any workaround to get it to work? Or it's Active Admin problem?

arogachev commented 8 years ago

Related issues - https://github.com/activeadmin/activeadmin/issues/4291 and https://github.com/activeadmin/activeadmin/issues/4177.

lucasmazza commented 8 years ago

@arogachev looks like active admin has a virtual dependency on devise with ~> 3.2, but now it should be something like >= 3.2 https://github.com/activeadmin/activeadmin/blob/rails-5-rspec/lib/active_admin/dependency.rb#L3-L5

seanlinsley commented 8 years ago

The virtual dependency has been fixed in the latest PR commits: https://github.com/activeadmin/activeadmin/pull/4254 (diff link)

arogachev commented 8 years ago

@seanlinsley Thanks for that! At least I will stay on rails-5-rspec branch for now and update to the latest version.

nclsjstnn commented 8 years ago

i've followed this guide to make it work with rails5: https://rrott.com/blog/ror/rails-5-api-with-activeadmin-integration.html