heroku undefined method `name' for User - ruby-on-rails

In my app it was User model without 'name' field, when I added this field by migration. On my localhost my sign up form works fine, but on heroku I have this log:
ActionView::Template::Error (undefined method `name' for #<User:0x0000000518fb00>):
Rendered users/new.html.haml within layouts/application (3.1ms)
5: = f.input :name, required: 'true'
6: = f.input :email, required: 'true'
3: %h1 Sign up
4: = simple_form_for #user do |f|
7: = f.input :password
8: = f.input :password_confirmation, required: 'true'
What I've tried:
heroku run rake db:migrate
heroku run rake db:reset
but nothing helped.

you also have to restart heroku after migrating - you'd want to run
heroku run rake db:migrate
heroku restart

Make sure you have done git add .. Then git status to make sure that all the files have been committed. Then try the push again. Then migrate again.

Related

heroku /api/comments:1 Failed to load resource: the server responded with a status of 500

I just pushed the latest to heroku and when testing the new comment functionality I got 500. Everything works fine on localhost. In the attached log it referencing jbuilder and it looks like the comments do not exit. Does anybody know what might cause it?
json.extract! comment, :id, :body, :author_id, :video_id, :created_at
#comments.each do |comment|
json.set! comment.id do
json.partial! 'comment', comment: comment
end
end
Did you run the migrations? heroku run rake db:migrate --app myApp

uninitialized constant Formtastic::I18n::SCOPES

Rails 6.0.1, Puma 4.3.0, Devise 4.7.1, ActiveAdmin 2.4.0, Formtastic 3.1.5.
Once again I am creating a Rails application. Created the foundation. A couple of models. Made a simple front-end for them. Next install Devise, ActiveAdmin.
In general, nothing unusual. Locally everything works fine.
But on the server, some kind of nonsense began to happen with ActiveAdmin.
In general, the application on the server is working fine. Through the console, I can create all the data. These data are successfully displayed on the site.
But if I go into ActiveAdmin...
Dashboard page displayed successfully. But if I go to the index page of any entity, then I will get the following error (from the log):
2019-11-19T00:55:04.216309411Z app[web.1]: web| I, [2019-11-19T00:55:04.198819 #14] INFO -- : [9ac98910-3a38-496d-9f5e-f276bc590ba7] Rendered vendor/bundle/ruby/2.5.0/gems/activeadmin-2.4.0/app/views/active_admin/resource/index.html.arb (Duration: 73.2ms | Allocations: 17729)
2019-11-19T00:55:04.216369240Z app[web.1]: web| I, [2019-11-19T00:55:04.199305 #14] INFO -- : [9ac98910-3a38-496d-9f5e-f276bc590ba7] Completed 500 Internal Server Error in 86ms (ActiveRecord: 5.8ms | Allocations: 19675)
2019-11-19T00:55:04.216376506Z app[web.1]: web| F, [2019-11-19T00:55:04.203841 #14] FATAL -- : [9ac98910-3a38-496d-9f5e-f276bc590ba7]
2019-11-19T00:55:04.216380926Z app[web.1]: web| [9ac98910-3a38-496d-9f5e-f276bc590ba7] ActionView::Template::Error (uninitialized constant Formtastic::I18n::SCOPES
2019-11-19T00:55:04.216385058Z app[web.1]: web| Did you mean? Sprockets):
2019-11-19T00:55:04.216388027Z app[web.1]: web| [9ac98910-3a38-496d-9f5e-f276bc590ba7] 1: insert_tag renderer_for(:index)
The entire log: https://pastebin.com/raw/buWSveBZ
Only one section for entities works - this is the show action. Only two actions for entities work - these are show and destroy. Everyone else catches the error that I showed above.
I absolutely don't understand what's the matter.
I successfully use the identical config/initializers/active_admin.rb file in two other Rails 6 applications. Below I will show an example of one of the file for ActiveAdmin:
# frozen_string_literal: true
ActiveAdmin.register User do
menu priority: 5
permit_params :email, :full_name, :roles, :password, :password_confirmation
remove_filter :users_roles
controller do
def find_resource
scoped_collection.find_by!(pkey: params[:id])
end
end
index do
selectable_column
id_column
column :pkey
column :email
column :full_name
column :roles
column :current_sign_in_at
column :sign_in_count
column :created_at
actions
end
form do |f|
f.inputs do
f.input :email
f.input :full_name
f.input :roles
f.input :password
f.input :password_confirmation
end
f.actions
end
end
I'm hope for your help.
For what it's worth, I have a rails 6 app that I hadn't touched in about a year and was getting a similar error despite never having an issue with my other rails app that I use regularly -- uninitialized constant Formtastic::Util
Commenter above's advice of running rails generate formtastic:install did the trick for me. Thanks!

Ruby on Rails: undefined method 'role' for Class

I'm haing a problem in my Ruby on Rails application. I have an entity called 'Hairdresser', with those properties:
irb(main):003:0> Hairdresser
=> Hairdresser(id: integer, name: string, surname: string, email: string, auth_token: string, password_digest: string, created_at: datetime, updated_at: datetime, facebook_id: string, first_login: boolean, role: string)
I also created some scaffold in order to create new Hairdresser entities, but when I click on "new hairdresser" I get the following error:
2016-03-17T09:14:43.063793+00:00 app[web.1]: ActionView::Template::Error (undefined method `role' for #<Hairdresser:0x007f9e20f2bc30>):
2016-03-17T09:14:43.063794+00:00 app[web.1]: 25: </div>
2016-03-17T09:14:43.063794+00:00 app[web.1]: 26: <div class="field">
2016-03-17T09:14:43.063795+00:00 app[web.1]: 27: <%= f.label :role %><br>
2016-03-17T09:14:43.063795+00:00 app[web.1]: 28: <%= f.text_field :role %>
2016-03-17T09:14:43.063795+00:00 app[web.1]: 29: </div>
Role is a property that I added AFTER the creation of the scaffold, but I also added it where it was supposed to be added (I think):
view/hairdressers/_form.html.erb
<div class="field">
<%= f.label :role %><br>
<%= f.text_field :role %>
</div>
view/hairdressers/index.html.erb, index.json.jsonbuilder, and in every other /view/hairdressers file.
The local version of the application is working, it could have something to do with the fact that Heroku is loading the production environment and on localhost I am running the development environment?
EDIT: this is the execution of heroku run rake --trace db:migrate
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Invoke db:load_config (first_time)
** Execute db:load_config
** Execute db:migrate
ActiveRecord::SchemaMigration Load (0.8ms) SELECT "schema_migrations".* FROM "schema_migrations"
** Invoke db:_dump (first_time)
** Execute db:_dump
Make sure the migrations are run on heroku. https://devcenter.heroku.com/articles/rake
heroku run rake --trace db:migrate

Problem adding a custom field to Devise while testing with cucumber

I added a username field to my Rails app that's using Devise. I did all the necessary steps like adding the field to the views, adding it to the User model, migrating my database, etc. Now, when I run through the registration steps manually everything works fine. But as soon as I try to write a feature in Cucumber I get a huge page of errors.
Here's a very short list of the errors I get when running my cucumber feature
Scenario: New user registration with valid info # features/user_access.feature:7
When I sign up as a new user with valid info # features/step_definitions/user_access_steps.rb:5
undefined method `username' for #<User:0x00000102f7dcf0> (ActionView::Template::Error)
/Users/Daniel/.rvm/gems/ruby-1.9.2-p136#Flow1/gems/activemodel-3.0.3/lib/active_model/attribute_methods.rb:364:in `method_missing'
/Users/Daniel/.rvm/gems/ruby-1.9.2-p136#Flow1/gems/activerecord-3.0.3/lib/active_record/attribute_methods.rb:46:in `method_missing'
/Users/Daniel/.rvm/gems/ruby-1.9.2-p136#Flow1/gems/actionpack-3.0.3/lib/action_view/helpers/form_helper.rb:1019:in `value_before_type_cast'
/Users/Daniel/.rvm/gems/ruby-1.9.2-p136#Flow1/gems/actionpack-3.0.3/lib/action_view/helpers/form_helper.rb:1007:in `value_before_type_cast'
/Users/Daniel/.rvm/gems/ruby-1.9.2-p136#Flow1/gems/actionpack-3.0.3/lib/action_view/helpers/form_helper.rb:915:in `block in to_input_field_tag'
/Users/Daniel/.rvm/gems/ruby-1.9.2-p136#Flow1/gems/actionpack-3.0.3/lib/action_view/helpers/form_helper.rb:915:in `fetch'
I have isolated the error to my Devise view. For some reason cucumber doesn't like the following lines
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
<%= devise_error_messages! % >
<p><%= f.label :username %><br />
<%= f.text_field :username %></p>
For some reason cucumber wont play nice with the :username label and text_field. All I am doing in my cucumber steps is going to the registration page and trying to fill in username with a name.
Any idea what is causing this error and how to fix it?
Have you updated the test database? rake db:test:prepare

Authlogic throwing errors on Heroku

Yes, I've read this.
This is what I'm getting in my production.log:
ActionView::TemplateError (undefined method `password' for #<User:0x2b0ddb58cdc0>) on line #11 of app/views/users/new.html.erb:
8: </p>
9: <p>
10: <%= f.label :password, "Password:" %><br />
11: <%= f.password_field :password %>
12: </p>
13: <p>
14: <%= f.label :password_confirmation, "Password again:" %><br />
When I try:
$ heroku rake db:reset RAILS_ENV=production
I get:
yeqynzfiku already exists
(in /disk1/home/slugs/109616_e6df6f2_8837/mnt)
Couldn't drop yeqynzfiku : #<ActiveRecord::StatementInvalid: PGError: ERROR: must be owner of database yeqynzfiku
: DROP DATABASE IF EXISTS "yeqynzfiku">
I don't know what this means. I've also tried
$ heroku rake db:reset
$ heroku rake db:migrate RAILS_ENV=production
$ heroku rake db:migrate
$ heroku rake gems:install (for what it's worth)
Everything works fine locally, both in development and production modes. I have a .gems file in my app, and when I first pushed to Heroku it seemed to install AuthLogic and Paperclip just fine.
Stumped. Thanks.
Sounds like you solved it, but with problems like this I find it handy do do a heroku restart.
For example, after running migrations with heroku rake db:migrate the app needs to be restarted before it will see those new columns.
Instead of db:reset try db:migrate VERSION=0 and db:migrate.
I think they have issues with reset because it tries to drop the db.
Also, you don't need to put RAILS_ENV=production it's the default AFAIK...
I had the same problem. I did a heroku restart and it worked perfectly.
Ah, had something to do with lots of things in the .gitignore file. Should have cleared it before pushing to Heroku.

Resources