Upgrading to Rails 7 and going through new_framework_defaults_7.0.rb and not understanding in Rails.application.config.action_dispatch.cookies_serializer = :json and "# If you have configured the serializer elsewhere, you can remove this."
Does the statement mean I can remove config/cookies_serializer.rbor the line innew_framework_defaults_7.0.rb`. I assume it needs to be set somewhere, but not twice.
Related
I've recently done an rails and ruby upgrade, we don't have strong params in the app (I know it's legacy).
So the way it's done in the app we have the following
def all_params_permitted(this_params = nil)
this_params = params if this_params == nil
this_params.permit!
this_params.each do |i, v|
if v.kind_in?([Hash, ActionController::Parameters])
all_params_permitted(v)
end
end
end
Which loops through all params and just accepts everything, all_params_permitted is called throughout the app I would love to add strong params but that's a no-go for now.
The issue in the above method is kind_in? the upgrade I did for this app was rails 5.0.3 to rails 6.1+ and went from ruby 2.2.6 to ruby 3.0.1 so I'm not sure why kind_in? has stopped working. This is an old app (built-in rails 2) so not sure if this has been deprecated.
Any help here would be great.
Edit
I have tried kind_of? but no dice.
the upgrade I did for this app was rails 5.0.3 to rails 6.1+ and went from ruby 2.2.6 to ruby 3.0.1
This is asking for trouble. It is strongly advised to try upgrading one minor version at a time (e.g. rails 5.0 --> 5.1 --> 5.2 --> 6.0 --> 6.1), otherwise you're very likely to break things with little information on why it's stopped working/how to fix it.
Likewise for ruby versions... At an absolute minimum I'd postpone the final upgrade to ruby v3 until your application works fine under ruby 2.7.
I'm not sure why kind_in? has stopped working
Nor am I, because that's a custom method. You haven't show us how it's defined, and nor have you shown us the error message, so it's impossible for me to say with confidence what's gone wrong.
My guess is that it's implemented something like this:
class Object
def kind_in?(classes)
classes.any? { |c| self.kind_of?(c) }
end
end
i.e. it's a little wrapper around the built-in kind_of? method.
And with that said, I still have no idea why this would have "stopped working" due to a ruby and/or rails upgrade.
Not sure about kind_in?, also didn't find any reference to that method, also as you have not posted the error so not sure about your issue. is_a?, kind_of?, instance_of? are few methods that check the object class but they check only a single class. Looking at your code one option for your condition could be:
if [Hash, ActionController::Parameters].include?(v.class)
which will check if it belongs to one of these classes.
To my knowledge, the new default in Rails 5 requires belongs_to associations to be present. I made a model with this association, but the problem is I don't get presence validation error when the associated field is empty. Instead I get a database Null Validation error since I set the _id column not to be null. (PG::NotNullViolation because I use Postgres)
Is this behaviour normal? I mean shouldn't I get the rails error only?
BTW, when I add presence validation for the field, it works as I expected.
According to the issue re weird behaviour of config belongs_to_required_by_default, it seems like one of your other gems intervenes in ActiveRecord::Base and causes the bug.
One of workarounds to the issue is to move the line
config.active_record.belongs_to_required_by_default = true
from initializers directly into application.rb.
This worked for me smoothly.
New Rails 5 applications come with a new initializer in
config/initializers/active_record_belongs_to_required_by_default.rb
If you upgraded a Rails 4 application or created your application with a beta version of Rails 5, then that file might be missing.
The configuration in that file enables the feature in question:
# Be sure to restart your server when you modify this file.
# Require `belongs_to` associations by default. This is a new Rails 5.0
# default, so it is introduced as a configuration option to ensure that apps
# made on earlier versions of Rails are not affected when upgrading.
Rails.application.config.active_record.belongs_to_required_by_default = true
Please check how belongs_to_required_by_default is configured in your application.
I faced with same problem.
You can move
config.active_record.belongs_to_required_by_default = false
to config/environments/needed_environment.rb or to config/application.rb
Helped for me!
I have a Rails model for a Recipe.
It has an attribute, views, which counts how many times it has been viewed.
In the show action of my controller, I fetch the model object normally:
#recipe = Recipe.find(params[:id])
Then I increase the view count and save:
#recipe.views = #recipe.views + 1
#recipe.save
This works without a hitch locally, but on Heroku, the save apparently doesn't happen.
No errors are thrown.
I can run this exact same code in the rails console on Heroku, and then it works.
The only way I can get it to work, is setting
config.cache_classes = false
in environmenst/production.rb
This is obvously not what I want, but I'm stumped about how to go from here.
I'm running Rails 3.2.8, Ruby 1.9.3 on the Cedar stack, using Postgresql 9.1 in both development and on production.
FWIW to future searchers looking for their own solution, Benjamin Tan's answer (in comments) of heroku restart was what worked for me when I had a similar problem.
Copying the answer from the edited question body in order to remove this question from the "Unanswered" filter:
UPDATE: Fixed
Turns out I had a file with another older definition of the controller in the app/controllers directory.
~ answer per Azzar
I'm trying to upgrade some tests as we move our app from Rails 2 on 1.8.7 to Rails 3 on Ruby 1.9.2. The tests basically ensure that database objects can be named with unicode characters, to provide international support.
The tests basically look like this:
#encoding: utf-8
'ä' =~ /\S/ # this passes
'ä' =~ \/w/ # this fails, apparently passed on 1.8.7
model = Model.create!(:name => '§äè®') # this causes a "Name must include at least one letter or number" validation error, which means Ruby (or Rails) is seeing the name as being blank
This is all fundamentally basic and very simplified for the purposes of posting here, but these are what fail. Is there anything else I need to be looking at here? I know Ruby doesn't play well with Unicode, but this pretty much has to be left in. Any help is appreciated.
Looks like this is working as intended:
http://redmine.ruby-lang.org/issues/show/3181
Changed to 'ä' =~ /\p{L}/ got it to work.
Im trying to figure out why ruby omnicompl only works sometimes for me.
Here it's working as expected.
But when I try the same thing on the same ivar 2 lines down I get "Pattern not found"
Both are done the same way, typing out #current_user_session.fiCtrl+X+O
I checked tpopes rails.vim github page for open/closed issues and tried to google it without luck.
My macvim and vim is compiled with +ruby
:echo &omnifunc returns rubycomplete#Complete
:Rails! returns rails.vim 4.3 (Rails-controller)
I have my complete vimdir on github for reference.
one would imagine that it's because in img2 it's now below the setting of the variable (#current_user_session = UserSession.find).
which means that as this is now an instance it's looking for instance methods, whereas before it was returning the class method.
e.g.
User.find # => fine
user = User.find
user.find # => Method not found
to demo the difference run these:
User.methods.sort
User.find.methods.sort
you'll see that it's quite different. put bluntly you're trying to look up 'find' for a user you have. "'tom'.find" doesn't make any sense.