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!
Related
As mentioned on title, I made a Rails 4 app that contains
mongoid (5.1.3)
devise (4.2.0)
simple_form (3.2.1)
I set up my app with commands below:
rails g mongoid:config
rails g simple_form:install --bootstrap
rails g devise:install
rails g devise User
rails g scaffold post title content:text user:references
I add the code below in user.rb model file to make association between two models:
embeds_many :posts
When I run app and create a user on it, then I visit http://localhost:3000/posts/new to create a new post, I got the error below:
Started GET "/posts/new" for 127.0.0.1 at 2016-07-29 19:54:21 +0300
Processing by PostsController#new as HTML
MONGODB | Adding localhost:27017 to the cluster.
MONGODB | localhost:27017 | mongoblog_development.find | STARTED | {"find"=>"users", "filter"=>{}}
MONGODB | localhost:27017 | mongoblog_development.find | SUCCEEDED | 0.0009257450000000001s
Rendered posts/_form.html.erb (134.4ms)
Rendered posts/new.html.erb within layouts/application (140.6ms)
Completed 500 Internal Server Error in 144ms
ActionView::Template::Error (undefined method `user_ids' for #<Post _id: 579b8a3d419a8f180afbb798, title: nil, content: nil>
Did you mean? user?):
4: <div class="form-inputs">
5: <%= f.input :title %>
6: <%= f.input :content %>
7: <%= f.association :user %>
8: </div>
9:
10: <div class="form-actions">
app/views/posts/_form.html.erb:7:in `block in _app_views_posts__form_html_erb__2731111319355307354_47423040086160'
app/views/posts/_form.html.erb:1:in `_app_views_posts__form_html_erb__2731111319355307354_47423040086160'
app/views/posts/new.html.erb:3:in `_app_views_posts_new_html_erb__3061427264044886497_70253725122920'
I searched it on search engine and here but there was nothing related with this issue. How can I fix it?
TEMPORARY SOLUTION:
Replacing embeds_many and embedded_in associations in model files with has_many and belongs_to makes the app work. By this replacement, it is possible to access Posts belongs to User or Users Post. I wonder whether it's possible to make association in first situation, using embeds_many and embedded_in.
I'm hitting a problem with my heroku deployment. Here is the log:
2014-04-29T16:41:59.782999+00:00 app[web.1]: Started GET "/lines/33/edit" for 94.174.113.168 at 2014-04-29 16:41:59 +0000
2014-04-29T16:41:59.782933+00:00 app[web.1]: Started GET "/lines/33/edit" for 94.174.113.168 at 2014-04-29 16:41:59 +0000
2014-04-29T16:41:59.804819+00:00 app[web.1]:
2014-04-29T16:41:59.804823+00:00 app[web.1]: ActiveRecord::RecordNotFound (Couldn't find User with id=0):
2014-04-29T16:41:59.804826+00:00 app[web.1]: app/views/lines/_history.html.erb:7:in `block in _app_views_lines__history_html_erb__3033746240219592358_69949428301200'
2014-04-29T16:41:59.804824+00:00 app[web.1]: config/initializers/paper_trail.rb:4:in `user'
2014-04-29T16:41:59.804854+00:00 app[web.1]: app/views/lines/_history.html.erb:4:in `_app_views_lines__history_html_erb__3033746240219592358_69949428301200'
2014-04-29T16:41:59.804828+00:00 app[web.1]: app/views/lines/_history.html.erb:4:in `each'
2014-04-29T16:41:59.804856+00:00 app[web.1]: app/views/lines/edit.html.erb:16:in `_app_views_lines_edit_html_erb__4129892984524241027_69949427894700'
2014-04-29T16:41:59.804869+00:00 app[web.1]: app/views/lines/_history.html.erb:4:in `each'
2014-04-29T16:41:59.804871+00:00 app[web.1]: app/views/lines/_history.html.erb:4:in `_app_views_lines__history_html_erb__3033746240219592358_69949428301200'
2014-04-29T16:41:59.804872+00:00 app[web.1]: app/views/lines/edit.html.erb:16:in `_app_views_lines_edit_html_erb__4129892984524241027_69949427894700'
2014-04-29T16:41:59.804875+00:00 app[web.1]:
2014-04-29T16:41:59.804874+00:00 app[web.1]:
2014-04-29T16:41:59.804857+00:00 app[web.1]:
2014-04-29T16:41:59.804858+00:00 app[web.1]:
2014-04-29T16:41:59.804864+00:00 app[web.1]:
2014-04-29T16:41:59.804865+00:00 app[web.1]: ActiveRecord::RecordNotFound (Couldn't find User with id=0):
2014-04-29T16:41:59.804866+00:00 app[web.1]: config/initializers/paper_trail.rb:4:in `user'
2014-04-29T16:41:59.804868+00:00 app[web.1]: app/views/lines/_history.html.erb:7:in `block in _app_views_lines__history_html_erb__3033746240219592358_69949428301200'
The offending initializer is as follows:
module PaperTrail
class Version < ActiveRecord::Base
def user
User.find self.whodunnit.to_i
end
def nextversion
self.next
end
end
end
Which is getting called in the _history view with the following:
<%= gravatar_for version.user %><%= link_to version.user.username, user_path(version.user) %>
This works fine in development and appears to work fine in production on most edit pages but on one I am encountering this error. I wanted to check the version in the console but it seems I can't access paper_trail Versions in the console at all, I can only assume this is because I don't have a Version model, only a table and a controller.
How can I fix this?
You are getting following error
ActiveRecord::RecordNotFound (Couldn't find User with id=0)
on the following method
def user
puts "Value of whodunnit is -----------> #{self.whodunnit}"
User.find self.whodunnit.to_i
end
which is called in
<%= gravatar_for version.user %><%= link_to version.user.username, user_path(version.user) %>
because self.whodunnit.to_i is returning 0. That means, whodunnit is either "" or nil or 0. Please set the correct value of whodunnit attribute. Also, you can check the current value of whodunnit by adding a logger or puts statement in PaperTrail::Version# user method.
You probably did not ran your seed.rb file (heroku run rake db:seed) to create the user or you just are looking for an user that is not defined anymore (like deleted for example).
When you delete a user that had id=0 the next user will have id=1.
Just for sure, o recommend that you enter on your console (heroku run console) and try to find it by yourself (Client.find(0)) or try to list all of them (Client.all) to see if the user with id=0 is defined.
Hope it helps
I am attempting to code a very simple way for a user to add html files to my Heroku app. These files would be saved in ./log for rendering later. I have tested my code locally (in both development and production), but when I attempt to upload a file on my Heroku hosted repo I get internal server error 500.
controller upload.rb:
class UploadController < ApplicationController
def index
render :file => 'upload/uploadfile.haml'
end
def uploadFile
file_param = params[:upload][:datafile]
post = DataFile.save(file_param)
render :text => "File has been uploaded successfully"
end
end
model data_file.rb:
class DataFile < ActiveRecord::Base
def self.save(upload)
# Changed Default Destination: [__RAILS_DIR__/log]
name = "./log/" + upload.original_filename
# can haz data directory?
require 'FileUtils'
FileUtils.mkdir_p(File.dirname(name))
File.open(name, "wb") { |f| f.write(upload.read) }
end
end
view uploadfile.haml:
%h1 File Upload
= form_for :upload,:url=>{:action => 'uploadFile'},:html => { :multipart => true } do |f|
%p
%label{:for => "upload_file"} Select File
\:
\#{f.file_field 'datafile'}
= f.submit "Upload"
heroku logs:
2012-08-07T14:13:20+00:00 app[web.1]: Started POST "/uploadFile" for 69.29.117.99 at 2012-08-07 14:13:20 +0000
2012-08-07T14:13:20+00:00 app[web.1]: Processing by UploadController#uploadFile as HTML
2012-08-07T14:13:20+00:00 app[web.1]: Parameters: {"utf8"=>"✓", "authenticity_token"=>"1dAXkMulNR0d8S/l6QC8JnpSDtNBaHoyKJezgnheR10=", "upload"=>{"datafile"=>#>}, "commit"=>"Upload"}
2012-08-07T14:13:20+00:00 app[web.1]: Completed 500 Internal Server Error in 3ms
2012-08-07T14:13:20+00:00 app[web.1]:
2012-08-07T14:13:20+00:00 app[web.1]: LoadError (no such file to load -- FileUtils):
2012-08-07T14:13:20+00:00 app[web.1]: app/models/data_file.rb:7:in save'
2012-08-07T14:13:20+00:00 app[web.1]: app/controllers/upload_controller.rb:8:inuploadFile'
2012-08-07T14:13:20+00:00 app[web.1]:
2012-08-07T14:13:20+00:00 app[web.1]:
2012-08-07T14:13:20+00:00 app[web.1]: cache: [POST /uploadFile] invalidate, pass
heroku: http://upload-example.herokuapp.com/
github: https://github.com/halterj1/upload
Please no trying to convince me to use paperclip or carrierwave, that does not answer my question. Any help would be greatly appreciated, thanks in advance guys!
You should read this article on heroku: https://devcenter.heroku.com/articles/read-only-filesystem
edit:
As stated in article.
Your app is compiled into a slug for fast distribution across the dyno manifold. The filesystem for the slug is read-only, which means you cannot dynamically write to the filesystem for semi-permanent storage. The following types of behaviors are not supported:
Caching pages in the public directory
Saving uploaded assets to local disk (e.g. with attachment_fu or paperclip)
Writing full-text indexes with Ferret
Writing to a filesystem database like SQLite or GDBM
Accessing a git repo for an app like git-wiki
There are two directories that are writeable: ./tmp and ./log (under your application root). If you wish to drop a file temporarily for the duration of the request, you can write to a filename like #{RAILS_ROOT}/tmp/myfile_#{Process.pid}. There is no guarantee that this file will be there on subsequent requests (although it might be), so this should not be used for any kind of permanent storage.
I've a rails 3.1 app on Heroku, I keep getting an 500 error in production which I can't recreate in dev.
When I try to perform an update action in one of my controllers I get a 500. I get the following from heroku logs -
2011-12-05T13:52:35+00:00 app[web.1]: Completed 500 Internal Server Error in 15ms
2011-12-05T13:52:35+00:00 app[web.1]:
2011-12-05T13:52:35+00:00 app[web.1]: NoMethodError (undefined method `updated?' for #<ActiveRecord::Associations::HasOneAssociation:0x00000004058800>):
2011-12-05T13:52:35+00:00 app[web.1]: app/controllers/cars_controller.rb:81:in `block in update'
2011-12-05T13:52:35+00:00 app[web.1]: app/controllers/cars_controller.rb:80:in `update'
The update action on my cars controller is -
def update
#car = Car.find_by_url_identifier(params[:id])
respond_to do |format| #**line 80**
if #car.update_attributes(params[:car]) #**line 81**
CarMailer.gift_confirmation(#car).deliver
format.html { redirect_to(thanks_path(#car.url_identifier)) }
else
format.html { render action: "edit" }
end
end
end
The parameters being posted are -
{"utf8"=>"✓",
"_method"=>"put",
"authenticity_token"=>"RTXCVvdsKQHc8CxHLeYS9WuztcrI1b4H8SHsdfsKWu+Iz4=",
"car"=>{"name"=>"dgdfsdfsd",
"email"=>"test#test.com",
"recipient_attributes"=>{"name"=>"fdsfsd",
"address1"=>"sdfsdfdsf",
"address2"=>"dsfdsfsdf",
"city"=>"sdfdsf",
"postcode"=>"sdfds"},
"gift_id"=>"2",
"message"=>"fsdfsdfdsf",
"terms"=>"1"},
"commit"=>"submit",
"id"=>"test5"}
My car model looks like this -
class Car < ActiveRecord::Base
validates :name, :presence =>true, :on => :update
validates :url_identifier, :presence =>true, :on => :create
has_one :recipient
belongs_to :gift
accepts_nested_attributes_for :recipient
accepts_nested_attributes_for :gift
def to_param
self.url_identifier
end
end
Any idea how I can fix this? Apart from looking at herokus logs, how else can I debug this?
Oddly the app work for a while if I do a 'heroku restart'
I can't see anything wrong in the code. Since it works on your development machine, I am guessing it is something else. Some difference. Did you run your migrations on heroku?
After deploying on heroku, you have to run your migrations in a separate step. I am not sure if that would give this kind of error. Just guessing here.
I googled the error message. Have you had a look at this thread: http://ruby-forum.com/topic/81719 They had a similar problem and have posted their solution/hack. Might be worth a try.
It looks like you are trying to call the method update to an ActiveRecord::Associations object instead of (probably) the Car model, which is strange because you would think it would be fetched and called on the model if it isn't a method found in Arel.
You could try to debug this by using the production environment settings in your development environment by looking in config/enviroments/production.rb and using those settings for development.
You could also try and recreate the problem on heroku using heroku console
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