undefined method `countries_collection' for CountryStateSelect:Module - ruby-on-rails

am using the country_state_select gem on simple_form,though my authentication is done using devise,i get this error each time i try to load
the page with the country_select option
"undefined method `countries_collection' for CountryStateSelect:Module"
my code is below
f.input :country, collection: CountryStateSelect.countries_collection
but it never loads,i keep getting that error message.

Try
gem 'country_state_select', '3.0.0'
in your Gemfile.
I got the same error you did, so I tried the latest version and it works. bundle failed because of a conflict, though, so I had to bundle update and then it worked.

Related

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

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

Getting an error trying to Route a page (Rails Server)

I'm attempting to try Routing for the first time. I'm following along with a book from Learn-rails.com. Author says to delete what is in config/routes.rb and replace it with: `
LearnRails::Aplication.routes.draw do
root to: redirect('/about.html')
end
After I saved the file, and then refresh localhost:3000 I get this NameError page: http://imgur.com/6pCPAoP
It says:
Tip: add gem "binding_of_caller" to your Gemfile to enable the REPL
and local/instance variable inspection.
Which I did add, and did "bundle install". Then I tried to restart rails server in a new window, and now that won't work. If I remove what the Author said to add to the routes.rb file. Everything is fine. Does anyone have any ideas on what is going on? Thanks!
The screenshot clearly specifies, missing 'p' in LearnRails::Aplication is creating the issue. Just replace and it should work
There are some exception and the better_error is unable to show the error.
Add following line into gem file.
gem 'binding_of_caller', :platforms=>[:mri_19, :mri_20, :rbx]
Run 'bundle install'
Then check for the exception and post it here, I will try to help with that.

bootstrap_form error undefined method

1- I installed gem bootstrap_form
2- I wrote in application.css that line *= require bootstrap_form before the */
3- in my html.erb
<%= bootstrap_form_for(#guardian, :url => student_guardians_path(#student),
html: { class: 'form-horizontal' },
method: :post) do |f| %>
And I am getting the following error : undefined methodbootstrap_form_for' for #<#:0xb31a80c>`
I was getting the same error. Fixed it by replacing
gem 'bootstrap-form'
by
gem 'bootstrap_form'
in my gemfile
I too was getting this error until I realized that I didn't restart the rails server. When I restarted the server, the error disappeared.
I recently had this issue and my problem was that bundle install seemed to be pulling v3.0.0, yet the most recent version on GitHub is listed as 2.3.0. Changing the appropriate line in my Gemfile to:
gem 'bootstrap_form', '~> 2.3.0'
Fixed the issue.
This issue was solved by writing the form's code correctly as shown in #sunny1304's comment bootstrap_form_for([#student,#guardian]. So if none of the existing answers worked for you this might be a hint or something to guide you.
Thanks to other contributors as their answers helped other users who faced the issue like me.

undefined method `simple_form_for' in RoR application

I've been browsing stack overflow and I noticed that many people use simple_form to make their lives easier.
I wanted to give it a try, so I added the gem to my gem file (gem 'simple_form') and sent:
rails generate simple_form:install --bootstrap
After reading the installation message, I created a view with the sample code from the readme:
<%= simple_form_for #user do |f| %>
<%= f.input :username %>
<%= f.input :password %>
<%= f.button :submit %>
<% end %>
Unfortunately, I get this error as soon as I try to load the page:
undefined method `simple_form_for' for #<#<Class:0x69dd688>:0x6903ac8>
What gives? How come it can't even recognize the method? I feel like I'm missing something really simply here. Could it be because i'm using bootstrap-sass? Do I need to include a helper in my user controller?
Did you restart your server?
Always keep in mind that after you install a gem or plugin.
Always restart your server
Its all because you didn't restart your server after installing new libraries such as simple_form, devise etc.
Try stop your server and restart it. Your code is perfect!. I encountered this several times. The solution is just restarting the server!.
You must restart your server after installing simple_form gem.
For any absolute beginners. This error will occur if you forgot to install simple_form. To rectify, add this to your Gemfile
gem 'simple_form'
and bundle install
To summarize all possibilities from above, hopefully this list is useful for other gems too.
Check if the simple_form gem is installed correctly
Find the gem in Gemfile and Gemfile.lock. Another way is to run this command in your terminal: bundle list | grep simple_form
If the output is empty
Possibly simple_form isn't installed in your project yet. Since the gem is an external gem, it isn't included in the Rails framework. Rails has its own form library (aka form_with and form_for).
To add simple_form to your project, open the Gemfile and add gem 'simple_form', then run the command in your terminal bundle install.
If the output isn't empty
Check if you have restart the server yet.
After restart the server, and you still not be able to access SimpleForm constant
Check if the gem is set to require: false in Gemfile. If so, remove this part and run bundle install.
You can check if the gem is loaded from rails console by typing rails console or rails c in your terminal.
After the console is loaded, type SimpleForm and hit Enter. In the case there is some errors complaining about the constant is undefined, refer to previous steps to 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