Sebastian
Joined
Activity
Seems like this is more an Shrine.rb problem, i adressed that on SO aswell:
Okay one last question :)
To avoid that cap production deploy is killing my Posts from the database i added
production:
adapter: sqlite3
database: /home/deploy/apps/Blogapp/releases/shared/db/production.sqlite3
as path into my database.yml and it works very well! But! My images, which i drag and drop into my posts arent saved with this method so after cap production deploy i got posts with not found images which is really bad.
The trix_attachments.js looks like that:
$(document).ready(function() {
Trix.config.attachments.preview.caption = {
name: false,
size: false
};
function uploadAttachment(attachment) {
var csrfToken = $('meta[name="csrf-token"]').attr('content');
var file = attachment.file;
var form = new FormData;
var endpoint = "/images";
form.append("Content-Type", file.type);
form.append("image[image]", file);
xhr = new XMLHttpRequest;
xhr.open("POST", endpoint, true);
xhr.setRequestHeader("X-CSRF-Token", csrfToken);
xhr.upload.onprogress = function(event) {
var progress = event.loaded / event.total * 100;
return attachment.setUploadProgress(progress);
};
xhr.onload = function() {
if (this.status >= 200 && this.status < 300) {
var data = JSON.parse(this.responseText);
//getting the id for the image related to the post so it can be called later on:
var image_ids_input = $("#post_image_ids");
var image_ids = image_ids_input.val() ? JSON.parse(image_ids_input.val()) : []
image_ids.push(data.image_id);
image_ids_input.val(JSON.stringify(image_ids));
return attachment.setAttributes({
url: data.url,
href: data.url
});
}
};
return xhr.send(form);
};
document.addEventListener("trix-attachment-add", function(event) {
var attachment = event.attachment;
if (attachment.file) {
return uploadAttachment(attachment);
}
});
});
my image.rb model looks like this
`class Image < ApplicationRecord
include ::ImageUploader::Attachment.new(:image)
belongs_to :post, optional:true
end
`
my post model has an has_many:images relation
the images_controller.rb looks like this:
class ImagesController < ApplicationController
respond_to :json
def create
image_params[:image].open if image_params[:image].tempfile.closed?
@image = Image.new(image_params)
respond_to do |format|
if @image.save
format.json { render json: { image_id: @image.id, url: @image.image_url }, status: :ok }
else
format.json { render json: @image.errors, status: :unprocessable_entity }
end
end
end
private
def image_params
params.require(:image).permit(:image)
end
end
and the part of the posts_controller.rb that seems to matter here looks like this:
def create
@post = Post.new(post_params)
if @post.save
image_ids = params['post']['image_ids']
image_ids = image_ids.present? ? JSON.parse(image_ids) : nil
if image_ids.present?
Image.where(id: image_ids).update_all(post_id: @post.id)
end
redirect_to pages_all_posts_path
else
render "new"
end
end
seems like thats a very specific question ... cause the trix_attachment file was thankfully created and edited by Jacob who was really really supportitive and seems to be a genius !
if it helps that is my github:
https://github.com/WebSepp/Blogapp
Solved :) Thanks to you !
I now have the problem that whenever I deploye something with capistrano my Sqlite3 database disappears. I have already read that it is in a different folder or that there are problems with it.
Now I'm thinking about switching to MySql or Postgresql, but this seems quite difficult to me. I now have a frustrating day behind me, which led me to go back to a git version from yesterday ... and then I was very annoyed not to take a snapshot of my DO server. That set me back very much and the SSH key confusion continues again.
Nevertheless I would like to know if there is a simple workaround for the sqlite3 problem or if I should really try to change the database again. This seems to have some effect on the code as well. I already had them running locally. Only on the server it didn't work then and then, when I tried to undo everything via Git version control my website always crashed.
Thats the walk of pain ...
thank you :) i solved it by changing the yui requirement for sass !
Hey Folks,
I have always received great help here, so I hope that it will work out this time so shortly before the end. I would like to deploy my app on my server and use capistrano. However, I come across the following error(s) again and again and don't know how to fix it. First the error was that he couldn't find Yarn or something was wrong with the Yui Compressor. I then installed Yarn on my terminal and the error changed to this one when i try to "cap production deploy"
Caused by:
SSHKit::Command::Failed: rake exit status: 1
rake stdout: DEPRECATION WARNING: Sprockets method register_engine
is deprecated.
Please register a mime type using register_mime_type
then
use register_compressor
or register_transformer
.
https://github.com/rails/sprockets/blob/master/guides/extending_sprockets.md#supporting-all-versions-of-sprockets-in-processors
(called from block in class:Railtie at /home/deploy/apps/Blogapp/shared/bundle/ruby/2.5.0/gems/less-rails-2.8.0/lib/less/rails/railtie.rb:16)
DEPRECATION WARNING: You are using a deprecated processor interface Less::Rails::ImportProcessor.
Please update your processor interface:
https://github.com/rails/sprockets/blob/master/guides/extending_sprockets.md#supporting-all-versions-of-sprockets-in-processors
(called from block in class:Railtie at /home/deploy/apps/Blogapp/shared/bundle/ruby/2.5.0/gems/less-rails-2.8.0/lib/less/rails/railtie.rb:21)
Yarn executable was not detected in the system.
Download Yarn at https://yarnpkg.com/en/docs/install
/home/deploy/apps/Blogapp/shared/bundle/ruby/2.5.0/bin/rake: No such file or directory - java
rake aborted!
YUI::Compressor::RuntimeError: Command 'java -jar /home/deploy/apps/Blogapp/shared/bundle/ruby/2.5.0/gems/yui-compressor-0.12.0/lib/yui/../yuicompressor-2.4.8.jar --type css --charset utf-8 /tmp/yui_compress20180918-14505-sgrpkh' returned non-zero exit status
/home/deploy/apps/Blogapp/shared/bundle/ruby/2.5.0/gems/yui-compressor-0.12.0/lib/yui/compressor.rb:106:in block in compress'
streamify'
/home/deploy/apps/Blogapp/shared/bundle/ruby/2.5.0/gems/yui-compressor-0.12.0/lib/yui/compressor.rb:141:in
/home/deploy/apps/Blogapp/shared/bundle/ruby/2.5.0/gems/yui-compressor-0.12.0/lib/yui/compressor.rb:86:in compress'
call'
/home/deploy/apps/Blogapp/shared/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/yui_compressor.rb:49:in
/home/deploy/apps/Blogapp/shared/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/yui_compressor.rb:28:in call'
call_processor'
/home/deploy/apps/Blogapp/shared/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/processor_utils.rb:75:in
/home/deploy/apps/Blogapp/shared/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/processor_utils.rb:57:in block in call_processors'
reverse_each'
/home/deploy/apps/Blogapp/shared/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/processor_utils.rb:56:in
/home/deploy/apps/Blogapp/shared/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/processor_utils.rb:56:in call_processors'
load_from_unloaded'
/home/deploy/apps/Blogapp/shared/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/loader.rb:134:in
/home/deploy/apps/Blogapp/shared/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/loader.rb:60:in block in load'
fetch_asset_from_dependency_cache'
/home/deploy/apps/Blogapp/shared/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/loader.rb:317:in
/home/deploy/apps/Blogapp/shared/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/loader.rb:44:in load'
block in initialize'
/home/deploy/apps/Blogapp/shared/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/cached_environment.rb:20:in
/home/deploy/apps/Blogapp/shared/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/cached_environment.rb:47:in load'
find_asset'
/home/deploy/apps/Blogapp/shared/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/base.rb:66:in
/home/deploy/apps/Blogapp/shared/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/base.rb:73:in find_all_linked_assets'
block in find'
/home/deploy/apps/Blogapp/shared/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/manifest.rb:142:in
/home/deploy/apps/Blogapp/shared/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/legacy.rb:114:in block (2 levels) in logical_paths'
block in stat_tree'
/home/deploy/apps/Blogapp/shared/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/path_utils.rb:228:in
/home/deploy/apps/Blogapp/shared/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/path_utils.rb:212:in block in stat_directory'
each'
/home/deploy/apps/Blogapp/shared/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/path_utils.rb:209:in
/home/deploy/apps/Blogapp/shared/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/path_utils.rb:209:in stat_directory'
stat_tree'
/home/deploy/apps/Blogapp/shared/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/path_utils.rb:227:in
/home/deploy/apps/Blogapp/shared/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/legacy.rb:105:in each'
block in logical_paths'
/home/deploy/apps/Blogapp/shared/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/legacy.rb:105:in
/home/deploy/apps/Blogapp/shared/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/legacy.rb:104:in each'
logical_paths'
/home/deploy/apps/Blogapp/shared/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/legacy.rb:104:in
/home/deploy/apps/Blogapp/shared/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/manifest.rb:140:in find'
compile'
/home/deploy/apps/Blogapp/shared/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/manifest.rb:186:in
/home/deploy/apps/Blogapp/shared/bundle/ruby/2.5.0/gems/sprockets-rails-3.2.1/lib/sprockets/rails/task.rb:68:in block (3 levels) in define'
with_logger'
/home/deploy/apps/Blogapp/shared/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/rake/sprocketstask.rb:147:in
/home/deploy/apps/Blogapp/shared/bundle/ruby/2.5.0/gems/sprockets-rails-3.2.1/lib/sprockets/rails/task.rb:67:in block (2 levels) in define'
'
/home/deploy/apps/Blogapp/shared/bundle/ruby/2.5.0/gems/rake-12.3.1/exe/rake:27:in
/home/deploy/.rvm/gems/ruby-2.5.1/gems/bundler-1.16.5/lib/bundler/cli/exec.rb:74:in load'
kernel_load'
/home/deploy/.rvm/gems/ruby-2.5.1/gems/bundler-1.16.5/lib/bundler/cli/exec.rb:74:in
/home/deploy/.rvm/gems/ruby-2.5.1/gems/bundler-1.16.5/lib/bundler/cli/exec.rb:28:in run'
exec'
/home/deploy/.rvm/gems/ruby-2.5.1/gems/bundler-1.16.5/lib/bundler/cli.rb:424:in
/home/deploy/.rvm/gems/ruby-2.5.1/gems/bundler-1.16.5/lib/bundler/vendor/thor/lib/thor/command.rb:27:in run'
invoke_command'
/home/deploy/.rvm/gems/ruby-2.5.1/gems/bundler-1.16.5/lib/bundler/vendor/thor/lib/thor/invocation.rb:126:in
/home/deploy/.rvm/gems/ruby-2.5.1/gems/bundler-1.16.5/lib/bundler/vendor/thor/lib/thor.rb:387:in dispatch'
dispatch'
/home/deploy/.rvm/gems/ruby-2.5.1/gems/bundler-1.16.5/lib/bundler/cli.rb:27:in
/home/deploy/.rvm/gems/ruby-2.5.1/gems/bundler-1.16.5/lib/bundler/vendor/thor/lib/thor/base.rb:466:in start'
start'
/home/deploy/.rvm/gems/ruby-2.5.1/gems/bundler-1.16.5/lib/bundler/cli.rb:18:in
/home/deploy/.rvm/gems/ruby-2.5.1/gems/bundler-1.16.5/exe/bundle:30:in block in <top (required)>'
with_friendly_errors'
/home/deploy/.rvm/gems/ruby-2.5.1/gems/bundler-1.16.5/lib/bundler/friendly_errors.rb:124:in
/home/deploy/.rvm/gems/ruby-2.5.1/gems/bundler-1.16.5/exe/bundle:22:in <top (required)>'
load'
/home/deploy/.rvm/gems/ruby-2.5.1/bin/bundle:23:in
/home/deploy/.rvm/gems/ruby-2.5.1/bin/bundle:23:in <main>'
eval'
/home/deploy/.rvm/gems/ruby-2.5.1/bin/ruby_executable_hooks:24:in
/home/deploy/.rvm/gems/ruby-2.5.1/bin/ruby_executable_hooks:24:in `
Tasks: TOP => assets:precompile
(See full trace by running task with --trace)
rake stderr: Nothing written
Tasks: TOP => deploy:assets:precompile
(See full trace by running task with --trace)
The deploy has failed with an error: Exception while executing on host 104.248.180.170: rake exit status: 1
rake stdout: DEPRECATION WARNING: Sprockets method register_engine
is deprecated.
Please register a mime type using register_mime_type
then
use register_compressor
or register_transformer
.
https://github.com/rails/sprockets/blob/master/guides/extending_sprockets.md#supporting-all-versions-of-sprockets-in-processors
(called from block in class:Railtie at /home/deploy/apps/Blogapp/shared/bundle/ruby/2.5.0/gems/less-rails-2.8.0/lib/less/rails/railtie.rb:16)
DEPRECATION WARNING: You are using a deprecated processor interface Less::Rails::ImportProcessor.
Please update your processor interface:
https://github.com/rails/sprockets/blob/master/guides/extending_sprockets.md#supporting-all-versions-of-sprockets-in-processors
(called from block in class:Railtie at /home/deploy/apps/Blogapp/shared/bundle/ruby/2.5.0/gems/less-rails-2.8.0/lib/less/rails/railtie.rb:21)
Yarn executable was not detected in the system.
Download Yarn at https://yarnpkg.com/en/docs/install
/home/deploy/apps/Blogapp/shared/bundle/ruby/2.5.0/bin/rake: No such file or directory - java
rake aborted!
YUI::Compressor::RuntimeError: Command 'java -jar /home/deploy/apps/Blogapp/shared/bundle/ruby/2.5.0/gems/yui-compressor-0.12.0/lib/yui/../yuicompressor-2.4.8.jar --type css --charset utf-8 /tmp/yui_compress20180918-14505-sgrpkh' returned non-zero exit status
/home/deploy/apps/Blogapp/shared/bundle/ruby/2.5.0/gems/yui-compressor-0.12.0/lib/yui/compressor.rb:106:in block in compress'
streamify'
/home/deploy/apps/Blogapp/shared/bundle/ruby/2.5.0/gems/yui-compressor-0.12.0/lib/yui/compressor.rb:141:in
/home/deploy/apps/Blogapp/shared/bundle/ruby/2.5.0/gems/yui-compressor-0.12.0/lib/yui/compressor.rb:86:in compress'
call'
/home/deploy/apps/Blogapp/shared/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/yui_compressor.rb:49:in
/home/deploy/apps/Blogapp/shared/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/yui_compressor.rb:28:in call'
call_processor'
/home/deploy/apps/Blogapp/shared/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/processor_utils.rb:75:in
/home/deploy/apps/Blogapp/shared/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/processor_utils.rb:57:in block in call_processors'
reverse_each'
/home/deploy/apps/Blogapp/shared/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/processor_utils.rb:56:in
/home/deploy/apps/Blogapp/shared/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/processor_utils.rb:56:in call_processors'
load_from_unloaded'
/home/deploy/apps/Blogapp/shared/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/loader.rb:134:in
/home/deploy/apps/Blogapp/shared/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/loader.rb:60:in block in load'
fetch_asset_from_dependency_cache'
/home/deploy/apps/Blogapp/shared/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/loader.rb:317:in
/home/deploy/apps/Blogapp/shared/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/loader.rb:44:in load'
block in initialize'
/home/deploy/apps/Blogapp/shared/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/cached_environment.rb:20:in
/home/deploy/apps/Blogapp/shared/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/cached_environment.rb:47:in load'
find_asset'
/home/deploy/apps/Blogapp/shared/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/base.rb:66:in
/home/deploy/apps/Blogapp/shared/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/base.rb:73:in find_all_linked_assets'
block in find'
/home/deploy/apps/Blogapp/shared/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/manifest.rb:142:in
/home/deploy/apps/Blogapp/shared/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/legacy.rb:114:in block (2 levels) in logical_paths'
block in stat_tree'
/home/deploy/apps/Blogapp/shared/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/path_utils.rb:228:in
/home/deploy/apps/Blogapp/shared/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/path_utils.rb:212:in block in stat_directory'
each'
/home/deploy/apps/Blogapp/shared/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/path_utils.rb:209:in
/home/deploy/apps/Blogapp/shared/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/path_utils.rb:209:in stat_directory'
stat_tree'
/home/deploy/apps/Blogapp/shared/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/path_utils.rb:227:in
/home/deploy/apps/Blogapp/shared/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/legacy.rb:105:in each'
block in logical_paths'
/home/deploy/apps/Blogapp/shared/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/legacy.rb:105:in
/home/deploy/apps/Blogapp/shared/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/legacy.rb:104:in each'
logical_paths'
/home/deploy/apps/Blogapp/shared/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/legacy.rb:104:in
/home/deploy/apps/Blogapp/shared/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/manifest.rb:140:in find'
compile'
/home/deploy/apps/Blogapp/shared/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/manifest.rb:186:in
/home/deploy/apps/Blogapp/shared/bundle/ruby/2.5.0/gems/sprockets-rails-3.2.1/lib/sprockets/rails/task.rb:68:in block (3 levels) in define'
with_logger'
/home/deploy/apps/Blogapp/shared/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/rake/sprocketstask.rb:147:in
/home/deploy/apps/Blogapp/shared/bundle/ruby/2.5.0/gems/sprockets-rails-3.2.1/lib/sprockets/rails/task.rb:67:in block (2 levels) in define'
'
/home/deploy/apps/Blogapp/shared/bundle/ruby/2.5.0/gems/rake-12.3.1/exe/rake:27:in
/home/deploy/.rvm/gems/ruby-2.5.1/gems/bundler-1.16.5/lib/bundler/cli/exec.rb:74:in load'
kernel_load'
/home/deploy/.rvm/gems/ruby-2.5.1/gems/bundler-1.16.5/lib/bundler/cli/exec.rb:74:in
/home/deploy/.rvm/gems/ruby-2.5.1/gems/bundler-1.16.5/lib/bundler/cli/exec.rb:28:in run'
exec'
/home/deploy/.rvm/gems/ruby-2.5.1/gems/bundler-1.16.5/lib/bundler/cli.rb:424:in
/home/deploy/.rvm/gems/ruby-2.5.1/gems/bundler-1.16.5/lib/bundler/vendor/thor/lib/thor/command.rb:27:in run'
invoke_command'
/home/deploy/.rvm/gems/ruby-2.5.1/gems/bundler-1.16.5/lib/bundler/vendor/thor/lib/thor/invocation.rb:126:in
/home/deploy/.rvm/gems/ruby-2.5.1/gems/bundler-1.16.5/lib/bundler/vendor/thor/lib/thor.rb:387:in dispatch'
dispatch'
/home/deploy/.rvm/gems/ruby-2.5.1/gems/bundler-1.16.5/lib/bundler/cli.rb:27:in
/home/deploy/.rvm/gems/ruby-2.5.1/gems/bundler-1.16.5/lib/bundler/vendor/thor/lib/thor/base.rb:466:in start'
start'
/home/deploy/.rvm/gems/ruby-2.5.1/gems/bundler-1.16.5/lib/bundler/cli.rb:18:in
/home/deploy/.rvm/gems/ruby-2.5.1/gems/bundler-1.16.5/exe/bundle:30:in block in <top (required)>'
with_friendly_errors'
/home/deploy/.rvm/gems/ruby-2.5.1/gems/bundler-1.16.5/lib/bundler/friendly_errors.rb:124:in
/home/deploy/.rvm/gems/ruby-2.5.1/gems/bundler-1.16.5/exe/bundle:22:in <top (required)>'
load'
/home/deploy/.rvm/gems/ruby-2.5.1/bin/bundle:23:in
/home/deploy/.rvm/gems/ruby-2.5.1/bin/bundle:23:in <main>'
eval'
/home/deploy/.rvm/gems/ruby-2.5.1/bin/ruby_executable_hooks:24:in
/home/deploy/.rvm/gems/ruby-2.5.1/bin/ruby_executable_hooks:24:in `
Tasks: TOP => assets:precompile
(See full trace by running task with --trace)
rake stderr: Nothing written
** DEPLOY FAILED
My Capfile
# Load DSL and set up stages
require "capistrano/setup"
# Include default deployment tasks
require "capistrano/deploy"
# Load the SCM plugin appropriate to your project:
#
# require "capistrano/scm/hg"
# install_plugin Capistrano::SCM::Hg
# or
# require "capistrano/scm/svn"
# install_plugin Capistrano::SCM::Svn
# or
require "capistrano/scm/git"
install_plugin Capistrano::SCM::Git
# Include tasks from other gems included in your Gemfile
#
# For documentation on these, see for example:
#
# https://github.com/capistrano/rvm
# https://github.com/capistrano/rbenv
# https://github.com/capistrano/chruby
# https://github.com/capistrano/bundler
# https://github.com/capistrano/rails
# https://github.com/capistrano/passenger
#
require "capistrano/bundler"
require "capistrano/rvm"
require "capistrano/rails/assets"
require "capistrano/rails/migrations"
require "capistrano/passenger"
require "capistrano/puma"
# Load custom tasks from `lib/capistrano/tasks` if you have any defined
Dir.glob("lib/capistrano/tasks/*.rake").each { |r| import r }
My Deploy.rb
# Change these
server 'xxx.xxx.xxx', port: 22, roles: [:web, :app, :db], primary: true
set :repo_url, 'git@github.com:WebSepp/Blogapp.git'
set :application, 'Blogapp'
set :user, 'deploy'
set :puma_threads, [4, 16]
set :puma_workers, 0
# Don't change these unless you know what you're doing
set :pty, true
set :use_sudo, false
set :stage, :production
set :deploy_via, :remote_cache
set :deploy_to, "/home/#{fetch(:user)}/apps/#{fetch(:application)}"
set :puma_bind, "unix://#{shared_path}/tmp/sockets/#{fetch(:application)}-puma.sock"
set :puma_state, "#{shared_path}/tmp/pids/puma.state"
set :puma_pid, "#{shared_path}/tmp/pids/puma.pid"
set :puma_access_log, "#{release_path}/log/puma.error.log"
set :puma_error_log, "#{release_path}/log/puma.access.log"
set :ssh_options, { forward_agent: true, user: fetch(:user), keys: %w(~/.ssh/usa) }
set :linked_files, %w{config/master.key}
set :puma_preload_app, true
set :puma_worker_timeout, nil
set :puma_init_active_record, true # Change to false when not using ActiveRecord
## Defaults:
# set :scm, :git
# set :branch, :master
# set :format, :pretty
# set :log_level, :debug
# set :keep_releases, 5
## Linked Files & Directories (Default None):
# set :linked_files, %w{config/database.yml}
# set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}
namespace :puma do
desc 'Create Directories for Puma Pids and Socket'
task :make_dirs do
on roles(:app) do
execute "mkdir #{shared_path}/tmp/sockets -p"
execute "mkdir #{shared_path}/tmp/pids -p"
end
end
before :start, :make_dirs
end
namespace :deploy do
desc "Make sure local git is in sync with remote."
task :check_revision do
on roles(:app) do
unless `git rev-parse HEAD` == `git rev-parse origin/master`
puts "WARNING: HEAD is not the same as origin/master"
puts "Run `git push` to sync changes."
exit
end
end
end
desc 'Initial Deploy'
task :initial do
on roles(:app) do
before 'deploy:restart', 'puma:start'
invoke 'deploy'
end
end
desc 'Restart application'
task :restart do
on roles(:app), in: :sequence, wait: 5 do
invoke 'puma:restart'
end
end
before :starting, :check_revision
after :finishing, :compile_assets
after :finishing, :cleanup
after :finishing, :restart
end
# ps aux | grep puma # Get puma pid
# kill -s SIGUSR2 pid # Restart puma
# kill -s SIGTERM pid # Stop puma
My Gemfile:
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '2.5.1'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.2.0'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Use Puma as the app server
group :development do
gem "capistrano", "~> 3.7"
gem "capistrano-rails", "~> 1.2"
gem "capistrano-passenger", "~> 0.2.0"
gem "capistrano-yarn"
gem "capistrano-puma"
gem "capistrano-rvm"
#Add this if you"re using rbenv
end
gem 'puma'
gem 'sprockets-rails', :require => 'sprockets/railtie'
# Use SCSS for stylesheets
gem 'sass-rails'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'mini_racer', platforms: :ruby
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.2'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.5'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
#
gem 'jquery-rails', '~> 4.3', '>= 4.3.3'
#gem less style
gem 'therubyracer'
gem 'less-rails' #Sprockets (what Rails 3.1 uses for its asset pipeline) supports LESS
#Use twitter bootstrap
gem 'twitter-bootstrap-rails'
gem 'friendly_id', '~> 5.2.0'
gem 'will_paginate', '~> 3.1.0'
gem 'trix-rails', require: 'trix'
gem 'shrine'
gem 'devise'
gem 'timepiece'
gem 'social-share-button'
# Use ActiveStorage variant
# gem 'mini_magick', '~> 4.8'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.1.0', require: false
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
end
group :development do
# Access an interactive console on exception pages or by calling 'console' anywhere in the code.
gem 'web-console', '>= 3.3.0'
gem 'listen', '>= 3.0.5', '< 3.2'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
end
group :test do
# Adds support for Capybara system testing and selenium driver
gem 'capybara', '>= 2.15', '< 4.0'
gem 'selenium-webdriver'
# Easy installation and use of chromedriver to run system tests with Chrome
gem 'chromedriver-helper'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
My nginx.conf: (not sure if thats relevant probably not)
upstream puma {
server unix:///home/deploy/apps/Blogapp/shared/tmp/sockets/Blogapp-puma.sock;
}
server {
listen 80 default_server deferred;
# server_name example.com;
root /home/deploy/apps/Blogapp/current/public;
access_log /home/deploy/apps/Blogapp/current/log/nginx.access.log;
error_log /home/deploy/apps/Blogapp/current/log/nginx.error.log info;
location ^~ /assets/ {
gzip_static on;
expires max;
add_header Cache-Control public;
}
try_files $uri/index.html $uri @puma;
location @puma {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://puma;
}
error_page 500 502 503 504 /500.html;
client_max_body_size 10M;
keepalive_timeout 10;
}
I tried this tutorial:
https://www.digitalocean.com/community/tutorials/deploying-a-rails-app-on-ubuntu-14-04-with-capistrano-nginx-and-puma
And then i switched halfway to that one and tried my luck with that one cause it seems newer:
https://revs.runtime-revolution.com/deploy-your-rails-app-with-capistrano-5ad5d58e9b07
but didnt worked out aswell
Is it possible to take away the sign_up option and set the users fix in the back end?
I dont want others to have the possibility to sign up at my website, except i create the user in the database. I know there is something like activeadmin, but i think that is to complex for what i want to achieve
Hey, i want to have the possibility to add more functionality in my text editor trix.
I think about basic stuff as centering text etc. and more advanced stuff like post spotify songs or twitter feeds etc. is this possible ?
uh ehm, okay didnt know that, is there a guide which shows how to achieve that? looks promising! thank you for that information!
what i really dont like on trix is that it seems to be impossible to style content in it like centering words etc.
In addition to that i really would love to embed social media in my posts like twitter feeds, spotify etc but that seems to be not possible aswell
Wow, you can't imagine how much you helped me. Thank you. I think I learned a lot already, because I started to write my own blog as a Rails application, but I have to admit, that it was not a good idea to use it myself and to present it later to others, probably my experience with Rails is not enough. Currently, for example, I still have a lot of code that actually belongs in the controller in the view or? But I'm not sure where exactly to outsource it. Thats getting more and more an issue, i think one where i ran recently in is this line in all_posts.html.erb
<%= link_to image_tag(post.images.last.image_url), post %>
if the last post has no image the image_url wont work and rails is throwing an error, so yeah iam supposed to do an if post.images.last.present? or something, but i dont really know where, cause i think an if loop in the link_to isnt really possible.
Especially the all_posts.html.erb shouldnt be like it is currently right?
I mean if i would like to add some functionality i cant to that like for posts cause there is the posts_controller.
My whole structure seems to be a bit off, also my index page, or what is supposed to be my index page is reached under localhost:3000/posts while it would be better under localhost:3000 itself, or even /index or something like that right?
Anyway ill try to finalize it as good as i can and try to deploy it, so maybe i can try to use it - if so, i think many credits go to your wonderful help! I really appreciate it. - Maybe i should try to read more about the basics first, and then come back one day and optimize it - but obviously the try and error thing is more fun, at least if a little success results from it.
All in all, I have to admit to myself that I still understand very little about web development, but I saw your motivations post in another thread that I found really very inspiring. Thanks again for your incredible help :)
Man you are a genius! Thank you so much, cant express how much you helped me! Its totally working now! Thank you i really really appreciate it!
Now i can work on my other 1000 problems :P
Haha, damn now i got a pretty difficult problem, when i want to refer to post.content i often dont want to have the image but only the text, for example for the teasertext. How can i manage that one?
You are the best!
Thank you again, yeah unfortunately its still not working - i dont really get, why its sometimes :image and sometimes :images is that right?
DB still says no image, so something on the Uploader is still not correct. Maybe i missed something or did something wrong. :(
date_field is correct i think, it gives me the opportunity to select a date for my posts and order it by the date, which could be helpful if i dont want to have it orderd by the creation_date. Maybe the choice of the name wasnt a really smart move from me.
Old posts and images are not a problem, its everything just local right now to test it and set it up
Did i implemented the js correct? And did the images from the posts still should show up like normal in all_weeks where i call the content?
First of all thank you very much for your incredible efforts to help me!
Unfortunately there seems to be an error:
<%= image_tag post.images.offset(rand(post.images.count)).first.image_url if post.images.present? %>
shows up that "images" are not find. Maybe there is an error now with the photo uploader? Or the name image? Sometimes referred as image and sometimes as images, while images seems to be an issue, not sure.
The /new form is rendering perfectly and i still can drag an drop an image, but it wont show up anymore. Neither in the singleview, nor in the teaserbox on /index.
I updated my GitRepo again, i think my schema looks fine, but there has to be an error now with the upload in general right ?
Would really appreciate it if you could have a look.
Seems like something if really odd with the upload, cause when i look for Image.all in the DB there isnt any entry at all.
https://github.com/WebSepp/Blogapp
- i really should change the title of the thread cause its going in another direction now, which is hopefully also helpful for others using trix and shrine.
Sure man, sorry. Here is my SO Link: https://stackoverflow.com/questions/51912749/rails-calling-an-image-from-an-article-which-is-uploaded-in-the-article-via-shri/51912838#51912838
no, i get that inconsitency thing on the other hand i am not really sure why he is then referring to a create_photo migration, maybe thats what confusing me.
Ah my gitrepo is here: https://github.com/WebSepp/Blogapp
Thank you for your help i think my problem is to get the association between my post and the image.
someone at SO mentioned that:
# db/migrations/001_create_photos.rb
create_table :images do |t|
t.integer :imageable_id
t.string :imageable_type
t.text :image_data
t.text :image_signature
end
add_index :images, :image_signature, unique: true
# app/uploaders/image_uploader.rb
class ImageUploader < Shrine
plugin :signature
plugin :add_metadata
plugin :metadata_attributes :md5 => :signature
add_metadata(:md5) { |io| calculate_signature(io) }
end
# app/models/image.rb
class Image < ApplicationRecord
include ImageUploader::Attachment.new(:image)
belongs_to :imageable, polymorphic: true
validates_uniqueness_of :image_signature
end
Also for consistencies sake in your code either call it image or photo. Your uploader is called Photos but everywhere else it is called Image.
The last change you need is in your controller for it to accept an array of images instead of one image. To do that you need to simply use an array:
def show
@image = Image.order('RANDOM()').limit(1).first
end
private
def images_params
params.require(:images).permit(images: [)
end
But iam not really sure what he meant with the first part, do i have to change my create_image model ? And if so how do i migrate it like that without killing everything? I still find the migration thing pretty confusing to be honest.
Yeah well the problem is not to upload the images into my post, the problem is to call them later from the post. E.g. i have a box with a title field a description field and an image field. Now i want to get the title, the description and the image automatically from the post i created into that box. And everytime i create a post the title, description and the image of the box is changing.
I guess therefore i have to call the image FROM the post, which i had uploaded via trix and shrine nearly as chris described in his videos
Would this gem also help me if I created 4-6 teaser boxes on my main page, in which the last 4-6 most recent posts are displayed? That would be my final goal for the main page. The boxes would then simply have the title of the post, the first two lines and an image from the post. But I really need help again, because I have no idea how to address the image in order to load it dynamically into the box. Thank you for your great help! I'm slowly learning to really love Ruby on Rails and have a lot of fun in the ever new challenges I'm facing.
I would like to structure my blog so that I can assign posts I have created with Trix and Shrine to weeks.
I want to have 12 teaserboxes on my index page which can then be clicked and if I click on week 1, for example, only the posts that are assigned to week 1 are displayed.
What's the smartest way to go? Should I make an extra week model? And can I somehow make a sort of assignment while creating the post that this post is a post for week 1? Are there any instructions or tips on how to do this? I'm totally overwhelmed with it right now. Currently all my posts are listed under /posts.
Posted in Creating a Blog with Images ins Posts
Thank you for that source! Where do i have to fill this code in exactly? Is it enough to just add the css and the js to the tinymce.js and css? And how do i have to fill in the html?
In addition to that do i need something like shrine or is AS enough for my goals?