Formtastic::UnknownInputError in ActiveAdmin::Devise::Sessions#new - ruby-on-rails

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.

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.

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

Related

Rails: ArgumentError in UsersController#create wrong number of arguments (2 for 1)

I generated scaffold User with attributes name:string and email:string. After fulfilling the form in the browser and hitting Create User, following error occurs:
click
Any clue about what might have gone wrong?
This happens when using an older version of turbolinks gem.
Try updating the gem to the latest version.
Add the following to your Gemfile:
gem 'turbolinks', '~> 2.5.3'
Then, do:
bundle install
Then, restart the rails server and try again!

undefined method `enum' for #<Class:0x007f099c303390>

I am using in rails and getting following error:
undefined method `enum' for #<Class:0x007f03202a1190
Model
class Location < ActiveRecord::Base
enum status: [ :current, :preffered ]
end
How can i remove this error.
ActiveRecord::Enum was only introduced to Rails at commit db41eb8a, and so far this commit has only been released with Rails tag v4.1.0.beta1.
It's likely that the current Rails gem you're using does not yet have this commit, and so does not have the code for implementing enum.
To check to see which version of the Rails gem you have, run:
bundle show rails
I just ran bundle update and then bundle show rails, and I am showing:
[PATH TO YOUR GEMS]/rails-4.0.2
This version of the gem does not include the code with enum. You can see this by comparing what is in v4.0.2 with what is in v4.0.1.beta1. If you click on 'File Changed' and then do a search in the page for enum.rb, you'll see that that is completely newly added code.
If you want to ensure that you get the newly tagged version of Rails, you can modify your Gemfile so that your line for including rails looks like this:
gem 'rails', :git => 'git://github.com/rails/rails.git', :tag => 'v4.1.0.beta1'
After you do a bundle update, you can see by doing a bundle show rails that you have the following rails gem:
[PATH TO YOUR GEMS]/rails-f706d5f945c5
f706d5f945c5 is the commit that was tagged for release v4.1.0.beta1.
After you get this bleeding edge version of the Rails gem, you should have access to this enum functionality.
You can use this feature by copying the code in the file rails/activerecord/lib/active_record/enum plus these lines:
module ActiveRecord
class Base
extend ActiveRecord::Enum
end
end
to your app's lib/ directory and then require-ing it in your environment.rb file. Eg.: in config/environment.rb
require 'active_record_enum'
You may refer to this code we have in production.

Rails Gem not loading in rails app

I have written my own Gem called date_ninja which makes sure a date is returned in the correct when passing a date from excel. Testing the gem it works fine. For example opening irb, and calling require 'date_ninja' returns true and I am able to use.
DateNinja::DateDojo.date_format_validation(value).
This will either return an date or an exception.
In my Rails App, I have added the gem to my gemfile as so:
gem 'date_ninja', git: 'git#github.com:mpowered/date_dojo'
I then ran bundle install but when I use it, I get this:
DateNinja::DateDojo.date_format_validation(56423)
NameError: uninitialized constant DateNinja::DateDojo
from (pry):5:in `<main>'
If I open the Rails console and see if I can require 'date_ninja' it => false so I am guessing its not loading my gem even though I have bundled it. Am I missing a step?
Can you try replacing the line:
gem 'date_ninja', git: 'git#github.com:mpowered/date_dojo'
with
gem 'date_ninja', path: 'local/path/of/ninja'
If this works then something is not well set with git.

gem version dilemma with rails 3.1

I want to use ebayapi gem (https://github.com/codyfauser/ebay) with my rails 3.1 application.
If I add the gem in the Gemfile, rails doesn't run.
/Users/ssk/.rvm/gems/ree-1.8.7-2011.03/gems/money-1.7.1/lib/support/cattr_accessor.rb:7:in `cattr_reader': undefined method `id2name' for {:instance_writer=>true}:Hash (NoMethodError)
I removed the ebayapi gem and tried "require 'ebay'" but it said that "no such file to load".
Ebayapi gem works only with money 1.7.1 and I think that conflicts with rails 3.1 (maybe 3.0 as well).
Is there a way to workaround?
Thanks.
Sam
If it's truly incompatible, and you're up to fixing it yourself, then fork the projects in question on github, and update your Gemfile to point to your git repo (or even a local path to make editing a lot easier).
Here's an example:
gem 'money', :path => "~/dev/ruby/gems/money"
# or
gem 'money', :git => "git://github.com/my_account/money.git"
Once you've fixed it, send a pull request to the original project so they can include the fix.

Getting 'undefined method' error or 'no such file to load error' trying to use validates_timeliness gem

I'm trying to use the validates_timeliness gem and followed the install instructions in the documentation: https://github.com/adzap/validates_timeliness
gem 'validates_timeliness', '3.0.2'
bundle install
rails generate validates_timeliness:install
I was then able to successfully add rspec tests and get them to pass using the validates_datetime feature from the gem
However, when I go to my new view in a browser, I get the error:
undefined method 'validates_datetime' for #
I also tried adding require 'validates_timeliness' at the top of the model file and then later at the top of the controller file. In those cases I get the error: 'no such file to load -- validates_timeliness
Any help would be much appreciated, have been trying to do extensive googling.
As noted in the instructions, it must be installed as both a plugin and a gem. When installed as a gem alone, seems to work fine with RSpec, but not in the browser.
How I fixed:
So anyone else that runs into this problem may also try running this code from master to install as plugin:
rails plugin install git://github.com/adzap/validates_timeliness.git
adzap/validates_timeliness#installation

Resources