vhochstein / active_scaffold

Rails 4 Version of activescaffold supporting jquery
MIT License
156 stars 34 forks source link

Documentation / Helpers out of sync? #105

Closed RobertLowe closed 13 years ago

RobertLowe commented 13 years ago

Ran into a wall with helpers being documented differently than the master:

https://github.com/activescaffold/active_scaffold/blob/master/lib/active_scaffold/helpers/list_column_helpers.rb

  def column_override_name(column, old = false)
    "#{clean_class_name(column.active_record_class.name) + '_' unless old}#{clean_column_name(column.name)}_column"
  end

  def column_override(column)
    method = column_override_name(column)
    return method if respond_to?(method)
    old_method = column_override_name(column, true)
    if respond_to?(old_method)
      ActiveSupport::Deprecation.warn("You are using an old naming schema for overrides, you should name the helper #{method} instead of #{old_method}")
      old_method
    end
  end
  alias_method :column_override?, :column_override

https://github.com/vhochstein/active_scaffold/blob/master/lib/active_scaffold/helpers/list_column_helpers.rb

  def column_override(column)
    "#{column.name.to_s.gsub('?', '')}_column" # parse out any question marks (see issue 227)
  end

As you can see on vhochstein's fork, an override is works like email_column, whereas on the master and it runs like user_email_column, seems like things got mixed in with pre-v2.3

Regards

vhochstein commented 13 years ago

Well, thats a specific feature of activescaffold master branch.

It s not in my fork and so far on purpose cause I do not see any benefits.

So please use override names without controller name

RobertLowe commented 13 years ago

Which I agree with for brevity;

It's just rough having it not documented... perhaps noting it here is enough

vhochstein commented 13 years ago

Thanks, added it to the differences section in wiki

mobilemike commented 13 years ago

I've done some digging, and I think I found a problem here. I have two models that share a number of the same field names. Because Rails 3 now includes all helpers in all controllers, my overrides are conflicting. Any other way around this?

RobertLowe commented 13 years ago

Are you placing them all in ApplicationHelper or [Model]Helper?

A ghetto hack might be to check which class the column call is passing

 def email_column(record)
    if record.klass == User
       ...
    end
 end

But that's kind of ghetto

vhochstein commented 13 years ago

Why is that a ghetto hack? IMHO That s a clean way to manage it.

mobilemike commented 13 years ago

Everything is in [controller]_helper.rb files, but Rails 3 apparently just throws all helpers into all controllers. There was some back and forth on the lighthouse ticket, but no resolution.

But the klass checking code with a case statement might be a better solution for the helpers that require it, and not for those that don't. Then, move everything up to application_helper. It seems like it could be a DRYer solution.

For the moment, I've hacked the AS 2.3 method into my own fork and renamed all my methods to the [class]_[field]_column convention, but I'll check this out too.

vhochstein commented 13 years ago

You do not have to hack this into a special fork... You can just define an override in your application helper file.. eg. def column_override(column) end

RobertLowe commented 13 years ago

Why is that a ghetto hack? IMHO That s a clean way to manage it.

Haha, yah, it ain't that bad