Manually set updated_at in Rails

If it’s a one time thing you can turn record_timestamps on or off. ActiveRecord::Base.record_timestamps = false #set timestamps manually ActiveRecord::Base.record_timestamps = true When I ran into this issue with my app, I searched around for a bit and this seemed like it made the most sense to me. It’s an initializer that I can call … Read more

Passing a argument to a callback function [duplicate]

This is what you’d use the meta Keyword for. def parse(self, response): for sel in response.xpath(‘//tbody/tr’): item = HeroItem() # Item assignment here url=”https://” + item[‘server’] + ‘.battle.net/’ + sel.xpath(‘td[@class=”cell-BattleTag”]//a/@href’).extract()[0].strip() yield Request(url, callback=self.parse_profile, meta={‘hero_item’: item}) def parse_profile(self, response): item = response.meta.get(‘hero_item’) item[‘weapon’] = response.xpath(‘//li[@class=”slot-mainHand”]/a[@class=”slot-link”]/@href’).extract()[0].split(“https://stackoverflow.com/”)[4] yield item Also note, doing sel = Selector(response) is a waste … Read more

Is there a design pattern that deals with callback mechanism?

That would be the Observer Pattern – From Wikipedia The observer pattern (a subset of the asynchronous publish/subscribe pattern) is a software design pattern in which an object, called the subject, maintains a list of its dependents, called observers, and notifies them automatically of any state changes, usually by calling one of their methods. It … Read more

When should I use return false in jquery function?

According to jQuery Events: Stop (Mis)Using Return False (archived link), returning false performs three tasks when called: event.preventDefault(); event.stopPropagation(); Stops callback execution and returns immediately when called. The only action needed to cancel the default behaviour is preventDefault(). Issuing return false; can create brittle code. Usually you’d want just this: $(“a”).on( ‘click’, function (e) { … Read more

How do I make a before_action to run on all controllers and actions except one?

What you have to do is to set autheticate_user! on all controllers like that : class ApplicationController < ActionController::Base before_action :authenticate_user! … end And then on your HomeController you do that : class HomeController < ApplicationController skip_before_action :authenticate_user!, only: [:index] … end Hope this will help you !

before_destroy callback not stopping record from being deleted

In Rails 5 you have to throw :abort otherwise it won’t work. (even returning false) Also, you should add prepend: true to the callback, to make sure it runs before the dependent: :destroy on the parent models. Something like this should work: class Something < ApplicationRecord before_destroy :can_destroy?, prepend: true private def can_destroy? if model.something? … Read more

android is there any view callback when it’s destroyed?

View does not have a callback (except finalize(), but I don’t think that’s what you’re asking for). View has onDetachedFromWindow() when it is removed from the screen, but this is not related to it being destroyed — it could be attached again, which will call onAttachedToWindow(). Fragment has onDestroyView(), which may be more useful to … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)