Rails 4.0 Strong Parameters nested attributes with a key that points to a hash

My other answer was mostly wrong – new answer. in your params hash, :filename is not associated with another hash, it is associated with an ActiveDispatch::Http::UploadedFile object. Your last code line: def screenshot_params params.require(:screenshot).permit(:title, assets_attributes: :filename) is actually correct, however, the filename attribute is not being allowed since it is not one of the permitted … Read more

Rails Observer Alternatives for 4.0

Take a look at Concerns Create a folder in your models directory called concerns. Add a module there: module MyConcernModule extend ActiveSupport::Concern included do after_save :do_something end def do_something … end end Next, include that in the models you wish to run the after_save in: class MyModel < ActiveRecord::Base include MyConcernModule end Depending on what … Read more

Rails I18n validation deprecation warning

Important: Make sure your app is not using I18n 0.6.8, it has a bug that prevents the configuration to be set correctly. Short answer In order to silence the warning edit the application.rb file and include the following line inside the Rails::Application body config.i18n.enforce_available_locales = true The possible values are: false: if you want to … Read more

Rails: PG::UndefinedTable: ERROR: relation “…” does not exist

So the issue is happening because CreateOrganizations migration is being run before CreateActioncodes is executed. CreateActioncodes is to be run first thereby ensuring that the action codes table exists. The order in which migrations are run is based on the time stamp of the migration – as indicated in the name of the file. 20141014183645_create_users.rb … Read more

Postgres JSON data type Rails query

For any who stumbles upon this. I have come up with a list of queries using ActiveRecord and Postgres’ JSON data type. Feel free to edit this to make it more clear. Documentation to the JSON operators used below: https://www.postgresql.org/docs/current/functions-json.html. # Sort based on the Hstore data: Post.order(“data->’hello’ DESC”) => #<ActiveRecord::Relation [ #<Post id: 4, … Read more

Redis + ActionController::Live threads not dying

A solution I just did (borrowing a lot from @teeg) which seems to work okay (haven’t failure tested it, tho) config/initializers/redis.rb $redis = Redis.new(:host => “xxxx.com”, :port => 6379) heartbeat_thread = Thread.new do while true $redis.publish(“heartbeat”,”thump”) sleep 30.seconds end end at_exit do # not sure this is needed, but just in case heartbeat_thread.kill $redis.quit end … Read more