I'm trying to attach an avatar to a profile model. I had rails 5.2 application and updated to rails 6. Here is the form for uploading the avatar.
In the configuration, I require the active storage engine
require_relative 'boot'
require "rails"
# Pick the frameworks you want:
require "active_model/railtie"
require "active_job/railtie"
require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "action_view/railtie"
require "active_storage/engine"
# require "action_cable/engine"
require "sprockets/railtie"
require "rails/test_unit/railtie"
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
module ArtsySpace
class Application < Rails::Application
# Initialize configuration defaults for originally generated Rails version.
config.load_defaults 5.1
# Use Vips for processing variants.
config.active_storage.variant_processor = :vips
# Use ActiveStorage for file storage
config.active_storage.service
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
end
end
When I look for a profile avatar I can see it in the console. But when I check if is attached it returns false.
2.5.0 :004 > Profile.first.avatar.methods
Profile Load (0.4ms) SELECT "profiles".* FROM "profiles" ORDER BY "profiles"."id" ASC LIMIT $1 [["LIMIT", 1]]
=> [:detach, :blank?, :purge, :attach, :attachment, :purge_later, :attached?, :method_missing, :record, :name, :to_json, :to_param, :to_query, :deep_dup, :acts_like?, :with_options, :duplicable?, :present?, :presence, :html_safe?, :as_json, :__binding__, :pry, :in?, :presence_in, :instance_values, :instance_variable_names, :to_yaml, :pretty_print_cycle, :pretty_print_inspect, :pretty_print, :pretty_print_instance_variables, :try!, :try, :unloadable, :require_or_load, :load_dependency, :instance_variable_set, :instance_variable_defined?, :remove_instance_variable, :instance_of?, :kind_of?, :is_a?, :tap, :instance_variable_get, :public_methods, :instance_variables, :pretty_inspect, :method, :public_method, :define_singleton_method, :singleton_method, :public_send, :class_eval, :extend, :to_enum, :enum_for, :gem, :<=>, :===, :=~, :!~, :eql?, :respond_to?, :freeze, :inspect, :object_id, :send, :byebug, :remote_byebug, :debugger, :to_s, :display, :nil?, :hash, :class, :clone, :singleton_class, :itself, :dup, :taint, :yield_self, :untaint, :tainted?, :untrusted?, :untrust, :trust, :frozen?, :methods, :singleton_methods, :protected_methods, :private_methods, :!, :equal?, :instance_eval, :instance_exec, :==, :!=, :__id__, :__send__]
2.5.0 :005 > Profile.first.avatar.attached?
Profile Load (0.4ms) SELECT "profiles".* FROM "profiles" ORDER BY "profiles"."id" ASC LIMIT $1 [["LIMIT", 1]]
ActiveStorage::Attachment Load (0.5ms) SELECT "active_storage_attachments".* FROM "active_storage_attachments" WHERE "active_storage_attachments"."record_id" = $1 AND "active_storage_attachments"."record_type" = $2 AND "active_storage_attachments"."name" = $3 LIMIT $4 [["record_id", 1], ["record_type", "Profile"], ["name", "avatar"], ["LIMIT", 1]]
=> false
How can I attach Image to the profile avatar?
I had the following in production but not on development and that was causing the issue.
config.active_storage.service = :local
Related
I updated from Rails 5.0 to 5.2 and made very few changes, but one thing quit working. repopulateResidResto is called when an address (location) or person is created or updated. It still works on the Rails 5.0 version at Heroku but not on my updated version on my computer. I can see the method is called in the server logs, but nothing is written to the database. Selected from the Heroku logs:
Year Load (3.5ms) SELECT "years".* FROM "years" ORDER BY "years"."id" ASC LIMIT $1 OFFSET $2 [["LIMIT", 1000], ["OFFSET", 206]]
Year Load (2.6ms) SELECT "years".* FROM "years" ORDER BY id OFFSET $1 [["OFFSET", 207]]
Location Load (1.2ms) SELECT "locations".* FROM "locations" WHERE "locations"."id" = $1 LIMIT $2 [["id", 62], ["LIMIT", 1]]
Location Load (1.1ms) SELECT "locations".* FROM "locations" WHERE "locations"."id" = $1 LIMIT $2 [["id", 2], ["LIMIT", 1]]
(4.5ms) BEGIN
SQL (1.8ms) INSERT INTO "resto_resid_lines" ("person_id", "resto_date", "resid_date", "title_resto", "title_resid", "resto_name", "created_at", "updated_at", "resto_connection_id", "resid_connection_id", "resto_loc_id", "resid_loc_id", "lat_resto", "long_resto", "resto_address", "resid_address", "mid_date") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17) RETURNING "id" [["person_id", 34], ["resto_date", "1886-09-01"], ["resid_date", "1886-09-01"], ["title_resto", "Co-proprietor"], ["title_resid", "Resident"], ["resto_name", ""], ["created_at", "2019-02-20 05:10:40.148200"], ["updated_at", "2019-02-20 05:10:40.148200"], ["resto_connection_id", 259], ["resid_connection_id", 258], ["resto_loc_id", 2], ["resid_loc_id", 62], ["lat_resto", "34.052265"], ["long_resto", "-118.243408"], ["resto_address", "11 W First St"], ["resid_address", "23 Sepulveda "], ["mid_date", "1886-09-01"]]
(2.2ms) COMMIT
The log on on my Mac with Rails 5.2. I imagine the ROLLBACK is a problem, but don't understand what triggers it:
Year Load (0.3ms) SELECT "years".* FROM "years" ORDER BY "years"."id" ASC LIMIT $1 OFFSET $2 [["LIMIT", 1000], ["OFFSET", 206]]
↳ app/controllers/application_controller.rb:19
Year Load (0.4ms) SELECT "years".* FROM "years" ORDER BY id OFFSET $1 [["OFFSET", 207]]
↳ app/controllers/application_controller.rb:47
Location Load (0.4ms) SELECT "locations".* FROM "locations" WHERE "locations"."id" = $1 LIMIT $2 [["id", 62], ["LIMIT", 1]]
↳ app/controllers/application_controller.rb:58
Location Load (0.3ms) SELECT "locations".* FROM "locations" WHERE "locations"."id" = $1 LIMIT $2 [["id", 2], ["LIMIT", 1]]
↳ app/controllers/application_controller.rb:64
(0.1ms) BEGIN
↳ app/controllers/application_controller.rb:53
Person Load (0.1ms) SELECT "people".* FROM "people" WHERE "people"."id" = $1 LIMIT $2 [["id", 34], ["LIMIT", 1]]
↳ app/controllers/application_controller.rb:53
(0.1ms) ROLLBACK
↳ app/controllers/application_controller.rb:53
Scoped order is ignored, it's forced to be batch order.
Year Load (0.2ms) SELECT "years".* FROM "years" ORDER BY "years"."id" ASC LIMIT $1 OFFSET $2 [["LIMIT", 1000], ["OFFSET", 208]]
↳ app/controllers/application_controller.rb:19
Line 19 is yearsBelow.find_each do |yearBelow|.
Line 47 is yearsBelow.each do |yearBelow|
Line 58 is :lat_resid => year.location.latitude.
Line 64 is :lat_resto => yearBelow.location.latitude.
Line 53 is the second RestoResidLine.create.
The controller (no changes made while upgrading to Rails 5.2):
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
include SessionsHelper
def repopulateResidResto
timeSpan = 12.months - 1.day # without 1.day pick up a year later, at least in early development
i = 1
RestoResidLine.delete_all
Year.unscope(:order).order('id').find_each do |year|
if year.resto
yearsBelow = Year.offset(i).unscope(:order).order('id') # default sort for year is date and without unscope really messes up things, could sort by lots of things, but id seems safe. Year is sorted by date, and we need that to be in the same sort
yearsBelow.find_each do |yearBelow|
foo_time =Time.parse(year.year_date.to_s)
bar_time = Time.parse(yearBelow.year_date.to_s)
avg = Time.at((foo_time.to_f + bar_time.to_f) / 2)
avg_date = Date.parse(avg.to_s) # if these dates are different use average for the lines
if (year.person_id == yearBelow.person_id) and (((yearBelow.year_date - timeSpan)..(yearBelow.year_date + timeSpan)).cover?year.year_date) and (!yearBelow.resto)
RestoResidLine.create(:person_id => year.person_id,
:resto_loc_id => year.location_id,
:resto_name => year.resto_name,
:resto_date => year.year_date,
:title_resto => year.title,
:lat_resto => year.location.latitude,
:long_resto => year.location.longitude,
:resto_address => year.location.address,
:resid_loc_id => yearBelow.location_id,
:resid_date => yearBelow.year_date,
:lat_resid => yearBelow.location.latitude,
:long_resid => yearBelow.location.longitude,
:resid_address => yearBelow.location.address,
:title_resid => yearBelow.title,
:mid_date => avg_date,
:resto_connection_id => year.id,
:resid_connection_id => yearBelow.id)
end
end
end
if year.resid
yearsBelow = Year.offset(i).unscope(:order).order('id')
yearsBelow.each do |yearBelow|
foo_time =Time.parse(year.year_date.to_s)
bar_time = Time.parse(yearBelow.year_date.to_s)
avg = Time.at((foo_time.to_f + bar_time.to_f) / 2)
avg_date = Date.parse(avg.to_s) # if these dates are different use average for the lines
if (year.person_id == yearBelow.person_id) and (((yearBelow.year_date - timeSpan)..(yearBelow.year_date + timeSpan)).cover?year.year_date) and (!yearBelow.resid)
RestoResidLine.create(:person_id => yearBelow.person_id,
:resto_loc_id => yearBelow.location_id,
:resto_name => yearBelow.resto_name,
:resto_date => yearBelow.year_date,
:title_resto => yearBelow.title,
:lat_resid => year.location.latitude,
:long_resid => year.location.longitude,
:resid_address => year.location.address,
:resid_loc_id => year.location_id,
:resid_date => year.year_date,
:title_resid => year.title,
:lat_resto => yearBelow.location.latitude,
:long_resto => yearBelow.location.longitude,
:resto_address => yearBelow.location.address,
:mid_date => avg_date,
:resto_connection_id => yearBelow.id,
:resid_connection_id => year.id)
end # if
end # yearBelow
end
i += 1
end
end
end
Gemfile:
source 'https://rubygems.org'
git_source(:github) do |repo_name|
repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
"https://github.com/#{repo_name}.git"
end
ruby '2.6.1'
gem 'rails', '~> 5.2.2'
gem 'puma', '~> 3.0'
source 'https://rails-assets.org' do
gem 'rails-assets-rearmed-js'
end
gem 'pg'
gem 'bootstrap-sass', '~> 3.4.0'
gem 'sassc-rails', '>= 2.0.0'
gem 'jquery-rails'
gem 'jquery-ui-rails'
gem 'turbolinks', '~> 5'
gem 'sdoc', '~> 0.4.0', group: :doc
gem 'bcrypt', '~> 3.1.7'
gem 'faker', '1.4.2'
gem 'mini_magick', '4.6.1'
gem 'will_paginate'
gem 'bootstrap-will_paginate', '0.0.10'
gem 'simple_form'
gem 'fuuu'
gem 'geocoder'
gem 'activerecord-postgis-adapter'
gem 'rgeo-geojson'
gem "fog-aws"
gem 'aws-sdk-s3', '~> 1'
gem 'carrierwave', '~> 1.0', '< 2.0'
gem 'pg-eyeballs'
gem 'leaflet-rails'
gem "responders"
group :development, :test do
gem 'rspec-rails'
gem 'database_cleaner'
gem 'dotenv-rails'
gem 'awesome_print'
gem 'super_awesome_print'
end
group :development do
gem 'web-console', '>= 3.3.0'
gem "better_errors"
gem 'binding_of_caller'
gem 'byebug', platform: :mri
gem 'pry-byebug'
gem "rails-erd"
gem 'annotate'
gem 'rubocop', require: false
end
group :production do
end
group :test do
gem 'minitest-reporters', '1.1.9'
gem 'guard', '2.13.0'
gem 'guard-minitest', '2.4.4'
gem 'rails-controller-testing', '0.1.1'
gem 'simplecov', :require => false
gem 'capybara'
end
How might I go about debugging this? Or what changes might be affecting this?
The line config.load_defaults 5.0 in config/application.rb was the cause of the problem. I don't know what the line does. Presumably load Rails 5.0 defaults. Why after going to the trouble of upgrading?
To get to this I tried to upgrade several times. At first going a bit too quickly and then slower and slower and following diffs and blogs on upgrading. What I finally did was go directly from 5.0 to 5.2, because going in two steps sent me in loops about bundler versions. And from reading blogs and seeing what happened in my earlier trials I was fairly certain not much changed for me in Rails 5.1.
I finally concluded that something happened in the rake app:update step. So I accepted all the defaults except I kept the old routes.rb. Then went through the diffs a file at a time and changed back to what I had in 5.0, relaunched server and went through the steps to trigger the RestoResidLine.create step.
I had tried several times over the last few months, but in the last few days went carefully through about three upgrade trials. Left to do is put back in what got left out of the rake app:update accepting of defaults. I think they are minor. No first I need to make sure can upload to heroku.
FWIW I wanted to get to 5.2 to get ActiveStorage.
I will show you my problem with two screenshots.
Here you can see the empty table in good shape:
empty table
When I fill it up with data DataTables doen't do any effect to the appearance anymore.
full table
All tables on other pages have the same problem.
Many thanks to everyone who tries to solve the issue!
Here is my Code:
Gemfile:
source 'https://rubygems.org'
gem 'rails', '5.1.2'
gem 'bcrypt', '3.1.11'
gem 'faker', '1.7.3'
gem 'carrierwave', '1.1.0'
gem 'mini_magick', '4.7.0'
gem 'fog', '1.40.0'
gem 'will_paginate', '3.1.5'
gem 'bootstrap-will_paginate', '1.0.0'
gem 'bootstrap-sass', '3.3.7'
gem 'puma', '3.9.1'
gem 'sass-rails', '5.0.6'
gem 'uglifier', '3.2.0'
gem 'coffee-rails', '4.2.2'
gem 'jquery-rails', '4.3.1'
gem 'turbolinks', '5.0.1'
gem 'jbuilder', '2.7.0'
group :development, :test do
gem 'sqlite3', '1.3.13'
gem 'byebug', '9.0.6', platform: :mri
end
group :development do
gem 'web-console', '3.5.1'
gem 'listen', '3.0.8'
gem 'spring', '2.0.2'
gem 'spring-watcher-listen', '2.0.1'
end
group :test do
gem 'rails-controller-testing', '1.0.2'
gem 'minitest-reporters', '1.1.14'
gem 'guard', '2.14.1'
gem 'guard-minitest', '2.4.6'
end
group :production do
# gem 'pg', '0.20.0'
# gem 'sqlite3', '1.3.13'
end
# for jquery-datatables-rails
gem 'jquery-ui-rails'
gem 'jquery-datatables-rails', github: 'rweng/jquery-datatables-rails'
gem 'jquery-turbolinks'
# for best_in_place
gem 'best_in_place'
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
Application.js:
// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, or any plugin's
// vendor/assets/javascripts directory can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file. JavaScript code in this file should be added after the last require_* statement.
//
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//
// require jquery
// require jquery_ujs
// require bootstrap
// keine Ahnung, ob rails-ujs auch benötigt wird??
// require rails-ujs
// require turbolinks
// require_tree .
//
//= require jquery
//= require jquery.turbolinks
//= require best_in_place
//= require jquery_ujs
//= require dataTables/jquery.dataTables
//= require bootstrap
//= require turbolinks
//= require_tree .
Application.css:
/*
* This is a manifest file that'll be compiled into application.css, which will include all the files
* listed below.
*
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, or any plugin's
* vendor/assets/stylesheets directory can be referenced here using a relative path.
*
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
* compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
* files in this directory. Styles in this file should be added after the last require_* statement.
* It is generally better to create a new file per style scope.
*
*= require_tree .
*= require_self
*= require jquery-ui/core
*= require dataTables/src/demo_table_jui
*/
Coffee Script:
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
jQuery ->
$('#preferences').dataTable
sPaginationType: "full_numbers"
bJQueryUI: true
jQuery ->
$('.best_in_place').best_in_place()
The View to the page:
<% if logged_in? %>
<div class="center jumbotron">
<p id="notice"><%= notice %></p>
<h1>Präferenzen bearbeiten</h1>
<table id="preferences" class="display">
<thead>
<tr>
<th>Institut</th>
<th>Präferenzwert</th>
<th></th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<% #current_user.preferences.each do |preference| %>
<tr>
<td><%= (Institute.find_by(id: preference.institute_id)).name %></td>
<td><%= preference.preference_value %></td>
<td><%= link_to 'Bearbeiten', edit_preference_path(preference) %></td>
</tr>
<% end %>
</tbody>
</table>
<br>
<%if #current_user.preferences.empty? %>
<%= button_to "Präferenzen erstellen", class: "btn btn-primary", :controller => 'preferences', :action => 'create_all'%>
<%end%>
</div>
<% end %>
Edit: Maybe these log files can help to solve the issue, first I upload the logfile when I get the empty preference table:
Started GET "/preferences" for 127.0.0.1 at 2018-02-22 12:06:33 +0100
Processing by PreferencesController#index as HTML
Rendering preferences/index.html.erb within layouts/application
[1m[36mUser Load (0.3ms)[0m [1m[34mSELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT ?[0m [["id", 2], ["LIMIT", 1]]
[1m[36mPreference Load (0.3ms)[0m [1m[34mSELECT "preferences".* FROM "preferences" WHERE "preferences"."user_id" = ?[0m [["user_id", 2]]
Rendered preferences/index.html.erb within layouts/application (49.2ms)
Rendered layouts/_rails_default.html.erb (215.1ms)
Rendered layouts/_shim.html.erb (0.4ms)
Rendered layouts/_header.html.erb (1.9ms)
Rendered layouts/_footer.html.erb (0.6ms)
Completed 200 OK in 300ms (Views: 293.2ms | ActiveRecord: 2.8ms)
And here ist the upload of the data-filled preference table:
Rendering preferences/index.html.erb within layouts/application
[1m[36mPreference Load (0.3ms)[0m [1m[34mSELECT "preferences".* FROM "preferences" WHERE "preferences"."user_id" = ?[0m [["user_id", 2]]
[1m[36mInstitute Load (0.6ms)[0m [1m[34mSELECT "institutes".* FROM "institutes" WHERE "institutes"."id" = ? LIMIT ?[0m [["id", 1], ["LIMIT", 1]]
[1m[36mInstitute Load (0.7ms)[0m [1m[34mSELECT "institutes".* FROM "institutes" WHERE "institutes"."id" = ? LIMIT ?[0m [["id", 2], ["LIMIT", 1]]
[1m[36mInstitute Load (0.3ms)[0m [1m[34mSELECT "institutes".* FROM "institutes" WHERE "institutes"."id" = ? LIMIT ?[0m [["id", 3], ["LIMIT", 1]]
[1m[36mInstitute Load (0.2ms)[0m [1m[34mSELECT "institutes".* FROM "institutes" WHERE "institutes"."id" = ? LIMIT ?[0m [["id", 4], ["LIMIT", 1]]
[1m[36mInstitute Load (0.1ms)[0m [1m[34mSELECT "institutes".* FROM "institutes" WHERE "institutes"."id" = ? LIMIT ?[0m [["id", 5], ["LIMIT", 1]]
[1m[36mInstitute Load (0.1ms)[0m [1m[34mSELECT "institutes".* FROM "institutes" WHERE "institutes"."id" = ? LIMIT ?[0m [["id", 6], ["LIMIT", 1]]
[1m[36mInstitute Load (0.2ms)[0m [1m[34mSELECT "institutes".* FROM "institutes" WHERE "institutes"."id" = ? LIMIT ?[0m [["id", 7], ["LIMIT", 1]]
[1m[36mInstitute Load (0.1ms)[0m [1m[34mSELECT "institutes".* FROM "institutes" WHERE "institutes"."id" = ? LIMIT ?[0m [["id", 8], ["LIMIT", 1]]
[1m[36mInstitute Load (0.1ms)[0m [1m[34mSELECT "institutes".* FROM "institutes" WHERE "institutes"."id" = ? LIMIT ?[0m [["id", 9], ["LIMIT", 1]]
[1m[36mInstitute Load (0.1ms)[0m [1m[34mSELECT "institutes".* FROM "institutes" WHERE "institutes"."id" = ? LIMIT ?[0m [["id", 10], ["LIMIT", 1]]
[1m[36mInstitute Load (0.1ms)[0m [1m[34mSELECT "institutes".* FROM "institutes" WHERE "institutes"."id" = ? LIMIT ?[0m [["id", 11], ["LIMIT", 1]]
[1m[36mInstitute Load (0.1ms)[0m [1m[34mSELECT "institutes".* FROM "institutes" WHERE "institutes"."id" = ? LIMIT ?[0m [["id", 12], ["LIMIT", 1]]
[1m[36mInstitute Load (0.1ms)[0m [1m[34mSELECT "institutes".* FROM "institutes" WHERE "institutes"."id" = ? LIMIT ?[0m [["id", 13], ["LIMIT", 1]]
[1m[36mInstitute Load (5.1ms)[0m [1m[34mSELECT "institutes".* FROM "institutes" WHERE "institutes"."id" = ? LIMIT ?[0m [["id", 14], ["LIMIT", 1]]
[1m[36mInstitute Load (0.7ms)[0m [1m[34mSELECT "institutes".* FROM "institutes" WHERE "institutes"."id" = ? LIMIT ?[0m [["id", 15], ["LIMIT", 1]]
[1m[36mInstitute Load (0.1ms)[0m [1m[34mSELECT "institutes".* FROM "institutes" WHERE "institutes"."id" = ? LIMIT ?[0m [["id", 16], ["LIMIT", 1]]
[1m[36mInstitute Load (0.2ms)[0m [1m[34mSELECT "institutes".* FROM "institutes" WHERE "institutes"."id" = ? LIMIT ?[0m [["id", 17], ["LIMIT", 1]]
[1m[36mInstitute Load (0.1ms)[0m [1m[34mSELECT "institutes".* FROM "institutes" WHERE "institutes"."id" = ? LIMIT ?[0m [["id", 18], ["LIMIT", 1]]
[1m[36mInstitute Load (0.2ms)[0m [1m[34mSELECT "institutes".* FROM "institutes" WHERE "institutes"."id" = ? LIMIT ?[0m [["id", 19], ["LIMIT", 1]]
[1m[36mInstitute Load (0.1ms)[0m [1m[34mSELECT "institutes".* FROM "institutes" WHERE "institutes"."id" = ? LIMIT ?[0m [["id", 20], ["LIMIT", 1]]
[1m[36mInstitute Load (0.2ms)[0m [1m[34mSELECT "institutes".* FROM "institutes" WHERE "institutes"."id" = ? LIMIT ?[0m [["id", 21], ["LIMIT", 1]]
Rendered preferences/index.html.erb within layouts/application (112.7ms)
Rendered layouts/_rails_default.html.erb (375.9ms)
Rendered layouts/_shim.html.erb (1.3ms)
Rendered layouts/_header.html.erb (4.9ms)
Rendered layouts/_footer.html.erb (3.2ms)
Completed 200 OK in 1398ms (Views: 515.5ms | ActiveRecord: 425.1ms)
You can fix that with js instead coffee. Make a js file called z-app.js, with:
document.addEventListener("turbolinks:load", function() {
$('#table-id').DataTable();
});
The trick is turbolinks:load because you should only load the table when your data is ready.
I'm using sitemap_generator gem to auto-generate the sitemap. It's already configured, tested and it's worked locally, but when I'm in production on my Dokku container, trying to run dokku run tradfood rake -s sitemap:refresh, following lines appear :
City Load (0.7ms) SELECT "cities".* FROM "cities" ORDER BY "cities"."id" ASC LIMIT $1 [["LIMIT", 1000]]
Recipe Load (2.5ms) SELECT "recipes".* FROM "recipes" ORDER BY "recipes"."id" ASC LIMIT $1 [["LIMIT", 1000]]
City Load (8.1ms) SELECT "cities".* FROM "cities" WHERE "cities"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
City Load (1.3ms) SELECT "cities".* FROM "cities" WHERE "cities"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
City Load (0.3ms) SELECT "cities".* FROM "cities" WHERE "cities"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
City Load (0.2ms) SELECT "cities".* FROM "cities" WHERE "cities"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
City Load (0.2ms) SELECT "cities".* FROM "cities" WHERE "cities"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
City Load (0.3ms) SELECT "cities".* FROM "cities" WHERE "cities"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
City Load (0.2ms) SELECT "cities".* FROM "cities" WHERE "cities"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
City Load (0.2ms) SELECT "cities".* FROM "cities" WHERE "cities"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
City Load (0.2ms) SELECT "cities".* FROM "cities" WHERE "cities"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
But nothing has been generated : when I run dokku run tradfood ls -all public, sitemap.xml stay to oct. 21.
My Dokku persistent storage still works with my image uploader on production (it record well new images, using carrierwave).
Here my sitemap.rb configuration :
# Set the host name for URL creation
SitemapGenerator::Sitemap.default_host = "https://tradfood.fr"
SitemapGenerator::Sitemap.create(:compress => false) do
# Put links creation logic here.
#
# The root path '/' and sitemap index file are added automatically for you.
# Links are added to the Sitemap in the order they are specified.
#
# Usage: add(path, options={})
# (default options are used if you don't specify)
#
# Defaults: :priority => 0.5, :changefreq => 'weekly',
# :lastmod => Time.now, :host => default_host
#
# Examples:
#
# Add '/articles'
#
# add articles_path, :priority => 0.7, :changefreq => 'daily'
#
# Add all articles:
#
# Article.find_each do |article|
# add article_path(article), :lastmod => article.updated_at
# end
add '/a-propos', :changefreq => 'monthly'
City.find_each do |city|
add city_path(city.name.parameterize), :lastmod => city.updated_at, :changefreq => 'weekly', :priority => 0.8
end
Recipe.find_each do |recipe|
add recipe_path(recipe.city.name.parameterize, recipe.name.parameterize), :lastmod => recipe.updated_at, :changefreq => 'daily'
end
end
That gist no longer exists. Mind using gist.github.com or pasting it in something native to stackoverflow instead?
I'm guessing:
You are not writing to persistent storage
You are not reading the file from persistent storage
I am trying to get acts as taggable on setup to work with my Rails 5 app.
I have a model called Randd::Field.rb, which has an attribute called :title in it. I want to use those titles as tags for my proposal model.
My Proposal.rb has:
class Proposal < ApplicationRecord
include Statesman::Adapters::ActiveRecordQueries
acts_as_taggable
acts_as_taggable_on :randd_maturities, :randd_fields, :randd_purposes, :randd_activities
My proposal form.html.erb has:
<%= f.collection_select :randd_field_list, Randd::Field.order(:title), :id, :title, {}, {multiple: true} %>
My proposal controller whitelists the randd_field_list with:
def proposal_params
params.require(:proposal).permit(:title, :randd_maturities_list, :randd_field_list, :randd_purposes_list, :randd_activities_list)
When I save all of this and try to add a tag to a proposal, I get an error. The server log shows:
Unpermitted parameter: randd_field_list
This doesn't make any sense because its a problem that comes up when the attribute is not whitelisted in the permitted params - which I have done.
Can anyone see what needs to be done in order to save tags via the proposal form?
I find the gem documentation confusing because it shows:
Setup
class User < ActiveRecord::Base acts_as_taggable # Alias for
acts_as_taggable_on :tags acts_as_taggable_on :skills, :interests
end
class UsersController < ApplicationController def user_params
params.require(:user).permit(:name, :tag_list) ## Rails 4 strong params usage end end
Why doesn't the permitted params include a :skill_list and an :interest_list given that those specific models are used as tags? Am I supposed to add "tag_list" to my proposal permitted params even when the only tags that can be added are from the titles defined in the specific models I've listed in:
acts_as_taggable_on :randd_maturities, :randd_fields, :randd_purposes, :randd_activities
The server log shows:
ActsAsTaggableOn::Tagging Load (1.6ms) SELECT "taggings".* FROM "taggings" WHERE "taggings"."taggable_id" = $1 AND "taggings"."taggable_type" = $2 [["taggable_id", 17], ["taggable_type", "Proposal"]]
ActsAsTaggableOn::Tag Load (1.7ms) SELECT "tags".* FROM "tags" INNER JOIN "taggings" ON "tags"."id" = "taggings"."tag_id" WHERE "taggings"."taggable_id" = $1 AND "taggings"."taggable_type" = $2 AND (taggings.context = 'randd_fields' AND taggings.tagger_id IS NULL) [["taggable_id", 17], ["taggable_type", "Proposal"]]
ActsAsTaggableOn::Tagging Load (2.8ms) SELECT "taggings".* FROM "taggings" WHERE "taggings"."taggable_id" = $1 AND "taggings"."taggable_type" = $2 [["taggable_id", 17], ["taggable_type", "Proposal"]]
ActsAsTaggableOn::Tag Load (3.0ms) SELECT "tags".* FROM "tags" INNER JOIN "taggings" ON "tags"."id" = "taggings"."tag_id" WHERE "taggings"."taggable_id" = $1 AND "taggings"."taggable_type" = $2 AND (taggings.context = 'randd_fields' AND taggings.tagger_id IS NULL) [["taggable_id", 17], ["taggable_type", "Proposal"]]
Randd::Field Load (1.6ms) SELECT "randd_fields".* FROM "randd_fields" ORDER BY "randd_fields"."title" ASC
Processing by ProposalsController#update as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"BF7l9/0QTVN3A==", "proposal"=>{"title"=>"asdf", "byline"=>"asdf", , "randd_field_list"=>["", "1"],
Unpermitted parameter: randd_field_list
You send an array for *_list parameters. Try to add [] for every _list in permit method:
params.require(:proposal).permit(
:title,
randd_maturities_list: [],
randd_field_list: [],
randd_purposes_list: [],
randd_activities_list: [])
so i havent found much documentation about using conditions on activerecord find methods for associated models, but i have found a variety of examples. although none of them seem to be working for me.
user has_one avatar
avatar belongs_to user
Avatar.find(:all, :include => :user, :conditions => {:user => {:login => 'admin'}})
returns the ridiculously long error
SQLite3::SQLException: no such column: user.login: SELECT "avatars"."id" AS t0_r0, "avatars"."user_id" AS t0_r1, "avatars"."featured" AS t0_r2, "avatars"."avatar_file_name" AS t0_r3, "avatars"."avatar_content_type" AS t0_r4, "avatars"."avatar_file_size" AS t0_r5, "avatars"."created_at" AS t0_r6, "avatars"."updated_at" AS t0_r7, "users"."id" AS t1_r0, "users"."login" AS t1_r1, "users"."email" AS t1_r2, "users"."crypted_password" AS t1_r3, "users"."password_salt" AS t1_r4, "users"."persistence_token" AS t1_r5, "users"."perishable_token" AS t1_r6, "users"."login_count" AS t1_r7, "users"."failed_login_count" AS t1_r8, "users"."last_request_at" AS t1_r9, "users"."current_login_at" AS t1_r10, "users"."last_login_at" AS t1_r11, "users"."current_login_ip" AS t1_r12, "users"."last_login_ip" AS t1_r13, "users"."created_at" AS t1_r14, "users"."updated_at" AS t1_r15 FROM "avatars" LEFT OUTER JOIN "users" ON "users".id = "avatars".user_id WHERE ("user"."login" = 'admin')
i have tried a variety of other patterns including
:conditions => "user.login == 'admin'"
but nothing is working.
this is with a rails 2.3.8 app, but rails3 is installed as well. so i have activerecord 3.0.0 & 2.3.8 installed. i thought this may be an issue, but it seems unlikely.
instead of
:user => {:login => 'admin'}
try
:users => {:login => 'admin'}
users
The standard Rails format for table names in the database itself is "all lower case, plural."
So you can debug your SQL error and see:
no such column: user.login
Since we know the table name is "users" the problem is that you're referencing table "user"
Fix depends on the version of Active Record. I prefer old school since it makes it more clear that the condition clause is SQL, not Ruby/Rails:
Avatar.find(:all, :include => :user,
:conditions => "users.login = 'admin'")
Note: Rails 3 is different from the above...
Added:
Remember that if you're looking up a login supplied as a parameter from the user, you must properly escape the parameter. Rails makes this easy:
user_login = "admin" # or, for example, params['user']
Avatar.find(:all, :include => :user,
:conditions => ["users.login = ?", user_login])