Rails 5.2: New records not saving after upgrade from 5.1.4 - ruby-on-rails-5.2

I upgraded my Rails 5.1.6 app on Ruby 2.4 to Rails 5.2 on Ruby 2.5.1 by making a new rails 5.2 app then transferring all the app files to it.
I noticed the following changes:
coffee script stopped working (no problem, I just changed to js)
creating new records stopped working, but editing existing records was ok. I just get the rollback error below:
2.5.1 :005 > Item.create(name: "asdf")
(0.3ms) BEGIN
(0.8ms) ROLLBACK ..
Is there anything in Rails 5.2 that affects new records in Active Record?

It turns out that optional: true has to be set for every belongs_to in Rails 5:
belongs_to :another_record, optional: true

Related

not able to add images to seeds.rb ruby on rails

I am trying to add images to my seeds.rb in my ruby on rails app. However the images do not save and I'm not able to show them in my app. When I run rails db:seed, I do not get an error. I am using active storage.
I hope you can help me out!
product-card.html.erb
seeds.rb
You want to persist the record before you do the attaching. Here's an example from my seed file:
person =
FactoryBot.create(
:person,
account:,
name: Faker::TvShows::FamilyGuy.unique.character
)
person.avatar.attach(
filename: 'avatar.jpg',
io: URI.open('https://api.lorem.space/image/face')
)

Ruby on Raills disabling the Assets-Pipeline

I try to update an old rails application.
It was original written with rails 2.3 and works now with rails 5.0.7
It does not use the asset pipeline, as there is not much css and js, and think it would make updating even more complex.
When trying to update to Rails 5.1, it seem now to wanting to use the asset pipeline, and throws errors:
<%= stylesheet_link_tag 'stylesheetfile.css' %>
ActionView::Template::Error (The asset "stylesheetfile.css" is not present in the asset pipeline.
):
I have already tried the following in application.rb
config.assets.enabled = false

devise views in rails fetching from rvm gem set

I was trying to install devise on my rails application.
So, when i was running my application ,the logs were showing that the rendered devise views are coming from /.rvm/gems/ruby 2.1.0/devise3.2.
i did the following
rails g devise:install
rails g devise shop
rails g devise:views shops
the logs:
Rendered /home/rawat/.rvm/gems/ruby-2.1.0/gems/devise-3.2.2/app/views/devise/shared/_links.slim (3.1ms)
Rendered /home/rawat/.rvm/gems/ruby-2.1.0/gems/devise-3.2.2/app/views/devise/sessions/new.html.slim within layouts/application (17.1ms)
Rendered static/_modal_user_account.html.slim (0.8ms)
Thanks in advance
It looks like you're trying to use what Devise calls scoped views. Make sure you have the following:
config/initializers/devise.rb
config.scoped_views = true
Devise README - Configuring Views

set up action mailer to work with rabbitmq in rails 3

i'm trying to set up actionmailer to work with rabbitmq.
in development.rb:
config.action_mailer.queue = Messaging::AmqpClient.instance
and in the the mailer:
class OrdersNotifier < ActionMailer::Base
default from: "me <noreply#e.me.com>"
def queue
Messaging::AmqpClient.instance.publish('ddd', 'test_msg')
end
to send a mail I am using:
OrdersNotifier.new_order_email_to_seller(self).deliver
bu I get :
undefined method `queue=' for ActionMailer::Base:Class
when trying to deliver the mail.
I might be wrong but "queue" is a rails 4 only feature that is by now removed from master branch.
See here:
http://blog.remarkablelabs.com/2012/12/asynchronous-action-mailer-rails-4-countdown-to-2013
The queue feature has been removed from the master branch, which means it will not be making the initial Rails 4.0 release.

sinatra-authentication gem not looking for correct views?

I am attempting to write a small blogging engine for myself in sinatra and mongoid and am trying to use the sinatra-authentication gem to do login/out.
I have gotten sinatra, mongoid, and haml all working but when I visit any sinatra-authentication page nginx throws an internal server error.
this is the error I am getting
Errno::ENOENT - No such file or directory - /opt/nginx/html/raptor.patrickarlt.com/views/layout.haml:
you can see all my files including more from my nginx error log here https://gist.github.com/854156
get '/' works confirming Sinatra is working
get '/haml' works confirming haml is working
get '/private' redirects to '/login' confirming sinatra-authentication is working
get '/login' internal server error
Ruby 1.9.2
Nginx 0.8.54
Passenger 3.0.2
sinatra-authentication assumes you're using a layout unless the current request is an XMLHttpRequest (see the code). You have two options:
Create a layout for your application in views/layout.haml as described a couple paragraphs down at http://sinatra-book.gittr.com/#templates
Override sinatra-authentication's use_layout? method as such:
module Sinatra
module Helpers
def use_layout?
false
end
end
end

Resources