Formtastic::UnknownInputError in ActiveAdmin::Devise::Sessions#new

偶尔善良 提交于 2019-12-24 17:28:04

问题


Using Rails 5.0.0.beta1.

Installed Active Admin and Devise. Here is Gemfile contents:

# Backend
gem 'activeadmin', '~> 1.0.0.pre2'

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

Followed instruction installation here.

rails g active_admin:install User
rake db:migrate
rake db:seed
rails server

When I'm trying to enter /admin, the following error appears:

Showing /usr/local/rvm/gems/ruby-2.2.2@mysite.com/gems/activeadmin-1.0.0.pre2/app/views/active_admin/devise/sessions/new.html.erb where line #10 raised:

Unable to find input class Input

Extracted source (around line #332): raise Formtastic::UnknownInputError, "Unable to find input #{$!.message}"

If we look at activeadmin-1.0.0.pre2/app/views/active_admin/devise/sessions/new.html.erb (line #10), nothing special is here:

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

What's wrong? Maybe Formtastic classes are not autoloaded for some reason? I tried to update Formtastic to the latest version, but error still remains.

I understand that using beta is kind of risky, but I want to try this out.


回答1:


Figured it out. Here are the available options:

1) Probably the best option. Just use Rails 4.2.5 and wait for stable release of Rails 5 and according gem updates.

2) Create the file app/active_admin/inputs/input.rb with the following contents:

module ActiveAdmin
  module Inputs
    class Input < ::Formtastic::Inputs::StringInput
    end
  end
end

Related info is available here.

It solves accessing login page error, you can now successfully login and view dashboard. However, if you try to enter Users section for example, you get another error:

NoMethodError: undefined method flat_map for #<ActionController::Parameters> from /usr/local/rvm/gems/ruby-2.2.2@mysite.com/gems/activeadmin-1.0.0.pre2/lib/active_admin/view_helpers/fields_for.rb:20:in fields_for_params

This is because ActionController::Parameters in Rails 5 no longer extends ActiveSupport::HashWithIndifferentAccess which includes Enumerable (which contains method flat_map). But I think this is not the only one error you will struggle with.

3) This error, error mentioned in 2) and some other errors were fixed already on rails-5-spec branch in this pull request, so I switched to using it instead in Gemfile:

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

Now the errors are gone.

Update: I choose 3rd option and it solves the problem on development server, but when I deployed application to production, error appeared again. I used the fix mentioned in 2) and now it's OK on production server too.




回答2:


css master branch of formtastic in your Gemfile

gem 'formtastic', git: 'git@github.com:justinfrench/formtastic.git', :branch => 'master'

and do bundle update and restart server rails s -d



来源:https://stackoverflow.com/questions/34529098/formtasticunknowninputerror-in-activeadmindevisesessionsnew

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!