Wolfgang Barth PRO
Joined 11/5/2017
Wolfgang Barth PRO said over 8 years ago on Polymorphic Associations :

I like it, routing via :modules is very elegant. It works for me in a normal rails application, but i can't get it work inside of a rails engine.

config/routes.rb from the engine:

Wobauth::Engine.routes.draw do
  resources :users do
    resources :authorities, module: :users
  end
end

Controllers:

module Wobauth
  class Users::AuthoritiesController < AuthoritiesController ...
  end
end
module Wobauth
  class AuthoritiesController < ApplicationController
   ...
  end
end

I get the following error:

uninitialized constant Authority
Extracted source (around line #269):
      names.inject(Object) do |constant, name|
        if constant == Object
          constant.const_get(name)
        else
          candidate = constant.const_get(name)
          next candidate if constant.const_defined?(name, false)

It works without specifying :modules, but this means i must place the logic in the main authorities_controller ... so its less elegant. Any idea?

Wolfgang.


Wolfgang Barth PRO said over 8 years ago on Polymorphic Associations :

Yeah, found it. The problem comes from cancancan/lib/cancan/controller_resource.rb in 


    def resource_class
      case @options[:class]
      when false
        name.to_sym
      when nil
        namespaced_name.to_s.camelize.constantize
      when String
        @options[:class].constantize
      else
        @options[:class]
      end
    end

The error cames from namespaced_name.to_s.camelize.constantize, which resolves to "Authority". I now set

module Wobauth
  class AuthoritiesController < ApplicationController
    skip_load_and_authorize_resource
    load_and_authorize_resource class: Wobauth::Authority ...

This sets the class name manually. Seems to work now. Thank you for the idea ;-)


Wolfgang Barth PRO said over 4 years ago on Hotwire Modals :
Yeah, I love this idea: render the complete modal via turbo_stream and then use connect() to auto-open the modal. I will give it a try.

Wolfgang Barth PRO said 11 months ago on Log Bench :
Nice gem, but very early development state. I'm using 0.2.1 and it eats all the cpu time. The automatic configuration don't work at all, manual configuration does. Since my log is now in json, I can't switch between tail -f and using log_bench easy. I will wait for a more stable version which eats less cpu time. But thanks for pointing out this very interesting gem.

Wolfgang Barth PRO said 8 months ago on Tags from Scratch :
before_validation on a virtual attribute only used in forms like :tag_list_input is dangerous. It works as long as you are only updating your model through form and controller. Other updates like updates via background job doesn't have a :tag_list_input and all assigned tags will be destroyed. Same problem exists with form variants without :tag_list_input (i.e. let only admin set tags etc.). My solution: don't execute set_tags_from_input if tag_list_input.nil? - an empty list from form is an empty string, but not nil.

def set_tags_from_input
  return if self.tag_list_input.nil?
  ...
end