helper functions not working

3 views
Skip to first unread message

dan

unread,
Oct 23, 2010, 3:15:34 AM10/23/10
to adva-cms
it looks like the my labels are all screwy and im having issues
getting started

after getting all the gems and stuff going and got the site to run,
the labels for the signup fields were missing
when guessing the fields and putting site name, user name and
password, i was getting user.valid errors caused by sha i believe
after not using a password, i was able to get a site up and running,
still with no labels
i can navigate to attempt to sign up or reset password, but theres
still big problems

the calling code looks like this:

<code>
<%= f.text_field :first_name, :label => true %>
<%= f.text_field :last_name, :label => true %>
<%= f.text_field :homepage, :label => true %>
<%= f.text_field :email, :label => true %>
<%= f.password_field :password, :label => true %>
</code>

the resultant html is this:

<code>
<label for="user_first_name"
tabindex="2">{:scope=>:activerecord, :attributes=>"user"}</
label><input id="user_first_name" name="user[first_name]" size="30"
tabindex="1" type="text" />
<label for="user_last_name"
tabindex="4">{:scope=>:activerecord, :attributes=>"user"}</
label><input id="user_last_name" name="user[last_name]" size="30"
tabindex="3" type="text" />
<label for="user_homepage"
tabindex="6">{:scope=>:activerecord, :attributes=>"user"}</
label><input id="user_homepage" name="user[homepage]" size="30"
tabindex="5" type="text" />
<label for="user_email"
tabindex="8">{:scope=>:activerecord, :attributes=>"user"}</
label><input id="user_email" name="user[email]" size="30" tabindex="7"
type="text" />
<label for="user_password"
tabindex="10">{:scope=>:activerecord, :attributes=>"user"}</
label><input id="user_password" name="user[password]" size="30"
tabindex="9" type="password" />
</code>

in the label tags looks like unparsed ruby code, but not a complete
statement
somehow, the helper functions are giving me poor results

perhaps this is relevant to the sha / failed user.valid issue i
noticed when first setting up

geoffd123

unread,
Oct 24, 2010, 6:46:50 AM10/24/10
to adva-cms
Hi Dan

What version of Rails are you using? I found this problem on 2.3.8,
but not on 2.3.4, but I do not know the Rails code well enough to see
what is causing it.

Cheers
Geoff

Dlineate

unread,
Oct 24, 2010, 8:42:49 AM10/24/10
to adva-cms
Yeah, there are a number of problems past 2.3.5 that make it unusable.
I've not tested 2.3.9 yet, but the comments people have left in the
release post do not leave me optimistic.

Your problems sound familiar. I think I've encountered myself - there
is a I18n translate issue introduced after 2.3.5 that effects
translation of field names on error.
These are related
http://github.com/svenfuchs/adva_cms/issues#issue/12
http://github.com/svenfuchs/adva_cms/issues#issue/13

It sounds like adva_cms 0.3.2 isn't getting much love because the
creators are starting from scratch for Rails3.

In the meantime, I'm using with rails 2.3.5 with the following 2
monkey patches in a custom plug-in.
Hope it helps.

vendor/plugins/custom_extensions/lib/form_helper.rb >>
module ActionView
module Helpers
class InstanceTag

# This is patch http://github.com/rails/rails/commit/f5714abc3d6dcda3851610419c00554ada8386ed
# which made it into Rails after -v2.3.5
# def to_label_tag(text = nil, options = {})
# options = options.stringify_keys
# tag_value = options.delete("value")
# name_and_id = options.dup
# name_and_id["id"] = name_and_id["for"]
# add_default_name_and_id_for_value(tag_value, name_and_id)
# options.delete("index")
# options["for"] ||= name_and_id["id"]
# content = (text.blank? ? nil : text.to_s) ||
method_name.humanize
# label_tag(name_and_id["id"], content, options)
# end

def to_label_tag(text = nil, options = {})
options = options.stringify_keys
tag_value = options.delete("value")
name_and_id = options.dup
name_and_id["id"] = name_and_id["for"]
add_default_name_and_id_for_value(tag_value, name_and_id)
options.delete("index")
options["for"] ||= name_and_id["id"]
#content = (text.blank? ? nil : text.to_s) ||
method_name.humanize
content = if text.blank?
i18n_label =
I18n.t("views.labels.#{object_name}.#{method_name}", :default => "")
i18n_label if i18n_label.present?
else
text.to_s
end
content ||= if object && object.class.respond_to?
(:human_attribute_name)
object.class.human_attribute_name(method_name)
end
content ||= method_name.humanize
label_tag(name_and_id["id"], content, options)
end

end
end
end
<<

vendor/plugins/custom_extensions/lib/nested_attributes.rb >>
# This patch is from upstream of 2.3.5. It can be removed once we
upgrade past it.
module ActiveRecord
module NestedAttributes #:nodoc:
module ClassMethods
# Defines an attributes writer for the specified association(s).
If you
# are using <tt>attr_protected</tt> or <tt>attr_accessible</tt>,
then you
# will need to add the attribute writer to the allowed list.
#
# Supported options:
# [:allow_destroy]
# If true, destroys any members from the attributes hash with
a
# <tt>_destroy</tt> key and a value that evaluates to +true+
# (eg. 1, '1', true, or 'true'). This option is off by
default.
# [:reject_if]
# Allows you to specify a Proc or a Symbol pointing to a
method
# that checks whether a record should be built for a certain
attribute
# hash. The hash is passed to the supplied Proc or the method
# and it should return either +true+ or +false+. When
no :reject_if
# is specified, a record will be built for all attribute
hashes that
# do not have a <tt>_destroy</tt> value that evaluates to
true.
# Passing <tt>:all_blank</tt> instead of a Proc will create a
proc
# that will reject a record where all the attributes are
blank.
# [:limit]
# Allows you to specify the maximum number of the associated
records that
# can be processes with the nested attributes. If the size of
the
# nested attributes array exceeds the specified limit,
NestedAttributes::TooManyRecords
# exception is raised. If omitted, any number associations can
be processed.
# Note that the :limit option is only applicable to one-to-
many associations.
# [:update_only]
# Allows to specify that the an existing record can only be
updated.
# A new record in only created when there is no existing
record. This
# option only works for on-to-one associations and is ignored
for
# collection associations. This option is off by default.
#
# Examples:
# # creates avatar_attributes=
# accepts_nested_attributes_for :avatar, :reject_if => proc { |
attributes| attributes['name'].blank? }
# # creates avatar_attributes= and posts_attributes=
#
accepts_nested_attributes_for :avatar, :posts, :allow_destroy => true
def accepts_nested_attributes_for(*attr_names)
options = { :allow_destroy => false, :update_only => false }
options.update(attr_names.extract_options!)

options.assert_valid_keys(:allow_destroy, :reject_if, :limit, :update_only)

attr_names.each do |association_name|
if reflection = reflect_on_association(association_name)
type = case reflection.macro
when :has_one, :belongs_to
:one_to_one
when :has_many, :has_and_belongs_to_many
:collection
end

reflection.options[:autosave] = true
self.nested_attributes_options[association_name.to_sym] =
options

# def pirate_attributes=(attributes)
#
assign_nested_attributes_for_one_to_one_association(:pirate,
attributes, false)
# end
class_eval %{
def #{association_name}_attributes=(attributes)
assign_nested_attributes_for_#{type}
_association(:#{association_name}, attributes)
end
}, __FILE__, __LINE__

add_autosave_association_callbacks(reflection)
else
raise ArgumentError, "No association found for name
`#{association_name}'. Has it been defined yet?"
end
end
end
end

# If update_only is true, a new record is only created when no
object exists,
# otherwise it will be updated
#
# If update_only is false and the given attributes include an
<tt>:id</tt>
# that matches the existing record’s id, then the existing record
will be
# modified. Otherwise a new record will be built.

def
assign_nested_attributes_for_one_to_one_association(association_name,
attributes)
options = self.nested_attributes_options[association_name]
attributes = attributes.with_indifferent_access
if options[:update_only]
if existing_record = send(association_name)
assign_to_or_mark_for_destruction(existing_record,
attributes, options[:allow_destroy])
else
unless reject_new_record?(association_name, attributes)
send("build_#{association_name}",
attributes.except(*UNASSIGNABLE_KEYS))
end
end
elsif attributes['id'].blank?
unless reject_new_record?(association_name, attributes)
method = "build_#{association_name}"
if respond_to?(method)
send(method, attributes.except(*UNASSIGNABLE_KEYS))
else
raise ArgumentError, "Cannot build association
#{association_name}. Are you trying to build a polymorphic one-to-one
association?"
end
end
elsif (existing_record = send(association_name)) &&
existing_record.id.to_s == attributes['id'].to_s
assign_to_or_mark_for_destruction(existing_record, attributes,
options[:allow_destroy])
end
end
end
end
<<

dan

unread,
Oct 24, 2010, 11:47:20 AM10/24/10
to adva-cms
im running:

ruby 1.9.1
rails 2.3.8

i have a box at work running rails 3 and was hoping to try this out.
hopefully it will be ready soon and maintained.

anyone have a good running demo to check out without installing?
Reply all
Reply to author
Forward
0 new messages