Hello fellow developers,
I have been stuck on this isssue for quite sometime now. All I want to do is somehow decrypt a column (ssn_or_ein) in my table (candidates) which was previously encrypted by the gem crypty_keeper.
https://github.com/jmazzi/crypt_keeper
What i have tried so far:
required the gem in Rails C and used the decrypt_table! against my Model
However, I am unable to catch the method
[pry(main)> Candidate.decrypt_table!
(0.2ms) BEGIN
Load (12.1ms) SELECT "candidates".* FROM "candidates" ORDER BY "candidates"."id" ASC LIMIT $1 [["LIMIT", 1000]]
(4.8ms) ROLLBACK
NameError: undefined local variable or method `crypt_keeper_fields' for #<Class:0x0000000007c5f038>
Did you mean? crypt_keeper
Also tried putting the pre-existing code back in my Application
class Candidate < ApplicationRecord
crypt_keeper :gateway_token, :ssn_or_ein, :e_in, encryptor: :active_support, key: ENV['ENCRYPTION_KEY'], salt: ENV['ENCRYPTION_SALT']
and I get an Active Support error
pry(main)> Candidate.decrypt_table!
(0.3ms) BEGIN
Load (609.8ms) SELECT "candidates".* FROM "candidates" ORDER BY "candidates"."id" ASC LIMIT $1 [["LIMIT", 1000]]
(0.3ms) ROLLBACK
ActiveSupport::MessageEncryptor::InvalidMessage: ActiveSupport::MessageEncryptor::InvalidMessage
from /home/niketa/.rvm/gems/ruby-2.6.7#raisethemoney5.2.5/gems/activesupport-5.2.6/lib/active_support/message_encryptor.rb:206:in `rescue in _decrypt'
Caused by ArgumentError: invalid base64
This is the error i am getting.
Any help or insight would be appreciated. Thanks
It looks like you have rows in your table that are not encrypted and those cause the Candidate.decrypt_table! call to fail. Did you maybe remove the crypt_keeper line from the Candidate class and then add entries? If so you'll have to remove them or skip them...
Related
I was trying to do a simple block on rails and Im getting an error and Im pretty sure is something basic but I lost my head now and since there isnt another programmer here I have nobody to share my idea. I have the following block:
#performances.where('creation >= ?', Date.yesterday).find_each do |per|
Im getting in better errors:
undefined method `row' for nil:NilClass
but when I open a simple rails console and do a query:
p = Performance.all.where('creation >= ?', Date.today)
I do get errors, anybody has an idea of why I cant get records when using greater or equal.
Now the weird thing is that it works perfectly If I use a less than or equal instead of greater, so if I do this:
#performances.where('creation <= ?', Date.yesterday).find_each do |per|
it works good but of course I dont want those records..
******************EDIT******************************************
I got more info from the erros:
Started GET "/performances.xlsx" for 127.0.0.1 at 2015-08-11 17:42:15 -0600
Processing by PerformancesController#index as XLSX
User Load (0.9ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT 1 [["id", 1]]
Performance Load (1.1ms) SELECT "performances".* FROM "performances" WHERE (creation = '2015-08-10') ORDER BY "performances"."id" ASC LIMIT 1000
Island Load (0.5ms) SELECT "islands".* FROM "islands" WHERE "islands"."id" = $1 LIMIT 1 [["id", 1]]
Rendered performances/index.xlsx.axlsx (17.4ms)
Completed 500 Internal Server Error in 30ms (ActiveRecord: 2.4ms)
NoMethodError - undefined method row' for nil:NilClass:
axlsx (2.0.1) lib/axlsx/workbook/worksheet/worksheet.rb:698:inrange'
axlsx (2.0.1) lib/axlsx/workbook/worksheet/worksheet.rb:615:in `[]'
Im using axlsx_rails
*******************************ANSWER**************************************
For everybody that has this problem it was obvious.. I was adding some code to an unexisting row in excel... just remove that and will get it done just as the error says
I am currently developing an application using NuoDB and Ruby on Rails
I am using the 'nuodb' gem and the 'activerecord-nuodb-adapter' to connect to the DB but I seem to be getting an error with the logs when executing commands.
For example, when I run the commands in my action:
x = GeneralLedger.where("id = ?", params[:id]).first
x.delete
This would output in the development logs:
[1m[35mGeneralLedger Load (2.4ms)[0m SELECT `general_ledgers`.* FROM `general_ledgers` WHERE (id = '48') FETCH FIRST 1 ROWS ONLY
[1m[35mSQL (0.3ms)[0m DELETE FROM `general_ledgers` WHERE `general_ledgers`.`id` = 48
This is okay, but when I execute the more direct approach which is:
GeneralLedger.find(params[:id]).delete
I keep get this error:
Could not log "sql.active_record" event. NoMethodError: undefined method `name' for 48:Fixnum <------ error
[1m[35mSQL (0.4ms)[0m DELETE FROM `general_ledgers` WHERE `general_ledgers`.`id` = 48
Here's another example of the log error I get when I am updating existing records:
Could not log "sql.active_record" event. NoMethodError: undefined method `name' for 21:Fixnum
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
[1m[35m (0.4ms)[0m UPDATE `general_ledgers` SET `accnt_dscr` = 'Other Expenses', `updated_at` = '2014-03-03 14:10:26' WHERE `general_ledgers`.`id` = 21
[1m[36m (0.3ms)[0m [1mcommit transaction[0m
Although the sql commands are executed and the records are deleted, I am unable to get the SQL commands generated.
I've tried using sqlite3 for testing and the
Could not log "sql.active_record" event.
error doesn't show up.
I've been trying to figure out where this logging error is coming from and I can't locate it. I'm not sure if I would just leave it alone since the commands are still executed.
This is a known issue with the driver that this being tracked here;
GitHub: GeneralLedger.find(params[:id]).delete throws error while logging the delete in ActiveRecord
To your point the Error is not preventing the action from being performed, it's just the output to the logs that is being omitted.
I'd expect further updates to be posted to the GitHub link above.
in my rspec testing, i have code like this
it 'test'
plan_calcs_from_file = File.read(file_location)
eval(plan_calcs_from_file)
end
but when i try to "eval(plan_calcs_from_file)", i get error like this
ActiveRecord::StatementInvalid Exception: Mysql2::Error: SAVEPOINT active_record_1 does not exist: ROLLBACK TO SAVEPOINT active_record_1
When i try in development mode this code work fine but in test mode this code get error. Why?
Try adding config.use_transactional_fixtures = false into the spec_helper.rb
You are using Mysql DDE statements (create/drop/truncate table) which will result in an implicit commit.
Because of the implicit commit, all savepoints of the current transaction are deleted.
I'm on Rails 3.1
I've pasted an example below, but Calling to_xml on any model throws this error. I've tried everything but I'm it's the sort of thing someone would have seen before. Does it ring any bells for anyone?
1.8.7 :004 > Person.first.to_xml
Person Load (2.0ms) SELECT `people`.* FROM `people` LIMIT 1
ArgumentError: wrong number of arguments (1 for 0)
from /home/khughes/.rvm/gems/ree-1.8.7-2012.02#rails31/gems/builder-3.0.0/lib/builder/xmlbase.rb:135:in `to_xs'
from /home/khughes/.rvm/gems/ree-1.8.7-2012.02#rails31/gems/builder-3.0.0/lib/builder/xmlbase.rb:135:in `_escape'
from /home/khughes/.rvm/gems/ree-1.8.7-2012.02#rails31/gems/builder-3.0.0/lib/builder/xmlbase.rb:140:in `_escape_quote'
from /home/khughes/.rvm/gems/ree-1.8.7-2012.02#rails31/gems/builder-3.0.0/lib/builder/xmlmarkup.rb:320:in `_attr_value'
from /home/khughes/.rvm/gems/ree-1.8.7-2012.02#rails31/gems/builder-3.0.0/lib/builder/xmlmarkup.rb:308:in `_insert_attributes'
from /home/khughes/.rvm/gems/ree-1.8.7-2012.02#rails31/gems/builder-3.0.0/lib/builder/xmlmarkup.rb:306:in `each'
from /home/khughes/.rvm/gems/ree-1.8.7-2012.02#rails31/gems/builder-3.0.0/lib/builder/xmlmarkup.rb:306:in `_insert_attributes'
from /home/khughes/.rvm/gems/ree-1.8.7-2012.02#rails31/gems/builder-3.0.0/lib/builder/xmlmarkup.rb:284:in `_special'
from /home/khughes/.rvm/gems/ree-1.8.7-2012.02#rails31/gems/builder-3.0.0/lib/builder/xmlmarkup.rb:250:in `instruct!'
from /home/khughes/.rvm/gems/ree-1.8.7-2012.02#rails31/gems/activemodel-3.1.1/lib/active_model/serializers/xml.rb:93:in `serialize'
from /home/khughes/.rvm/gems/ree-1.8.7-2012.02#rails31/gems/activerecord-3.1.1/lib/active_record/serializers/xml_serializer.rb:175:in `to_xml'
from (irb):4
had the same issue some time ago, do you have hpricot gem bundled into the project? if so, try to remove it from the Gemfile, run bundle and check if to_xml works
there's a solution that worked for me:
https://github.com/hpricot/hpricot/issues/53 ( see smeevil's post )
I'm using the awesome_nested_set rails 3 fork here: https://github.com/FreakyDazio/awesome_nested_set
I'm trying to rebuild the nesting per the installation instructions.
I went to console and typed in:
>>Comment.rebuild!
But that errors with:
ActiveRecord::StatementInvalid: PGError: ERROR: column "comments.created_at" must appear in the GROUP BY clause or be used in an aggregate function
LINE 2: HAVING COUNT("lft") > 1 ORDER BY comments.cr...
^
: SELECT "lft", COUNT("lft") FROM "comments" GROUP BY "lft"
HAVING COUNT("lft") > 1 ORDER BY comments.created_at DESC LIMIT 1
Any thoughts or ideas why?
Thanks
This same issues is reported in another fork of acts_as_nested_set (you seem to have all the bad luck. :) See this error report. He does mention a workaround you can put in your model:
def self.all_roots_valid?
if acts_as_nested_set_options[:scope]
roots.group_by{|record| scope_column_names.collect{|col| record.send(col.to_sym)}}.all? do |scope, grouped_roots|
each_root_valid?(grouped_roots)
end
else
each_root_valid?(roots)
end
end