lib/generators/templates/app/helpers/beautiful_helper.rb in beautiful_scaffold-0.2.2 vs lib/generators/templates/app/helpers/beautiful_helper.rb in beautiful_scaffold-0.2.3
- old
+ new
@@ -39,38 +39,51 @@
default_caption = attribute_name.capitalize
if is_belongs_to_column?(default_caption) then
default_caption = get_belongs_to_model(default_caption)
end
- caption = t(attribute_name, :default => default_caption)
+ caption = t(attribute_name, :default => default_caption).capitalize
strpath = model_name.pluralize + "_url"
strpath = namespace + '_' + strpath if not namespace.blank?
return link_to(
"#{csort} #{caption}".html_safe,
eval(strpath) + "?" +
CGI.unescape({:sorting => {:attribute => attribute_name.downcase,:sorting => opposite_sortstr}}.to_query)
).html_safe
end
- def ransack_field(model_name, attribute_name, f, caption = nil)
+ def ransack_field(path_of_model, attribute_name, f, caption = nil)
+ model_path = path_of_model.split("/")
+ model_name = model_path.last
+ model_path.delete(model_path.first)
+ model_name_for_ransack = model_path.join("_")
+
ar_model = model_name.classify.constantize
default_caption = caption
if default_caption.blank? then
default_caption = attribute_name.capitalize
if is_belongs_to_column?(default_caption) then
default_caption = get_belongs_to_model(default_caption)
end
end
- name_field = attribute_name
+ name_field = attribute_name
+ name_field_bk = attribute_name
+ label_field = attribute_name
+
+ if is_belongs_to_column?(name_field_bk) then
+ label_field = get_belongs_to_model(attribute_name)
+ end
+
+ name_field = model_name_for_ransack + "_" + name_field unless model_name_for_ransack.blank?
+
response = '<div class="control-group">'
- response += f.label name_field, t(attribute_name, :default => default_caption), :class => "control-label"
+ response += f.label name_field, t(label_field, :default => default_caption).capitalize, :class => "control-label"
response += '<div class="controls">'
-
type_of_column = ar_model.columns_hash[attribute_name].type unless ar_model.columns_hash[attribute_name].nil?
type_of_column ||= :other
case type_of_column
when :date, :datetime then
dt = (type_of_column == :datetime)
@@ -139,12 +152,12 @@
response += f.label name_field + "_eq_false", raw(f.radio_button((name_field + "_eq").to_sym, false)) + " " + h(t(:no, :default => "No")), :class => "checkbox inline"
response += f.label name_field + "_eq", raw(f.radio_button((name_field + "_eq").to_sym, nil)) + " " + h(t(:all, :default => "All")), :class => "checkbox inline"
when :string then
response += f.text_field((name_field + "_cont").to_sym, :class => "filter span12")
when :integer, :float, :decimal then
- if is_belongs_to_column?(name_field) then
- btmodel = get_belongs_to_model(name_field).classify.constantize
+ if is_belongs_to_column?(name_field_bk) then
+ btmodel = get_belongs_to_model(name_field_bk).classify.constantize
response += f.collection_select((name_field + "_eq").to_sym, btmodel.all, :id, :caption, { :include_blank => t(:all, :default => "All") }, { :class => "span12" })
elsif name_field == "id" then
response += f.text_field((name_field + "_eq").to_sym, :class => "filter span12")
else
response += '<div class="input-prepend">'
@@ -197,18 +210,18 @@
def get_belongs_to_model(column)
return column[0..-4]
end
- def build_treeview(obj, child_relation)
+ def build_treeview(obj, child_relation, caption_method = "caption")
out = '
<li id="treeelt_' + obj.id.to_s + '" data-id="' + obj.id.to_s + '">
- <a href="#" class="nopjax">' + obj.caption + '</a>
+ <a href="#" class="nopjax">' + obj.send(caption_method).to_s + '</a>
<ul>'
ar = obj.send(child_relation.to_sym)
ar = ar.order('position') if obj.class.column_names.include?("position")
for o in ar.all
- out += build_treeview(o, child_relation)
+ out += build_treeview(o, child_relation, caption_method)
end
out += '
</ul>
</li>'
return out.html_safe