I am using a serialized attribute in one of my models The serialized data is in the form of an array. I want to have a text_tag for each element contained in my serialized attribute. How would I construct the text_tag? My model name is ''questions''. The serialized attribute is "answers" So I might have: <% form tag %> <% text_tag ''question'', ''name'' %> <% text_tag ''question'', ''answers[0]'' %> <% text_tag ''question'', ''answers[1]'' %> It''s the last two I can''t figure out. I''m sure there is a clean, simple way of doing it. Slight complications - my stored array is actually an arrays within an array - storing the answer_name and correct_or_not. Some answers might have 2 answers, while others might have 5. Thanks very much, Steve http://www.smarkets.net -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060315/35d8f075/attachment.html
Mark Reginald James
2006-Mar-15 14:21 UTC
[Rails] Re: Populating text_tag with serialized data
Steve Odom wrote:> I am using a serialized attribute in one of my models The serialized > data is in the form of an array. I want to have a text_tag for each > element contained in my serialized attribute. How would I construct the > text_tag? > > My model name is ''questions''. The serialized attribute is "answers" > > So I might have: > > <% form tag %> > <% text_tag ''question'', ''name'' %> > <% text_tag ''question'', ''answers[0]'' %> > <% text_tag ''question'', ''answers[1]'' %> > > It''s the last two I can''t figure out. I''m sure there is a clean, simple > way of doing it. > > Slight complications - my stored array is actually an arrays within an > array - storing the answer_name and correct_or_not. Some answers might > have 2 answers, while others might have 5.<% form tag %> <% text_field ''question'', ''name'' %> <% text_field_tag ''question[answers][]'', @question.answers[0].first %> <% text_field_tag ''question[answers][]'', @question.answers[1].first %> which when POSTed will give you an array of answer_names in params[:question][:answers], into which you can (re-)insert the correct_or_not data. -- We develop, watch us RoR, in numbers too big to ignore.
Mark Reginald James
2006-Mar-15 14:31 UTC
[Rails] Re: Populating text_tag with serialized data
Steve Odom wrote:> I am using a serialized attribute in one of my models The serialized > data is in the form of an array. I want to have a text_tag for each > element contained in my serialized attribute. How would I construct the > text_tag? > > My model name is ''questions''. The serialized attribute is "answers" > > So I might have: > > <% form tag %> > <% text_tag ''question'', ''name'' %> > <% text_tag ''question'', ''answers[0]'' %> > <% text_tag ''question'', ''answers[1]'' %> > > It''s the last two I can''t figure out. I''m sure there is a clean, simple > way of doing it. > > Slight complications - my stored array is actually an arrays within an > array - storing the answer_name and correct_or_not. Some answers might > have 2 answers, while others might have 5.<%= form tag %> <%= text_field ''question'', ''name'' %> <%= text_field_tag ''question[answers][]'', @question.answers[0].first %> <%= text_field_tag ''question[answers][]'', @question.answers[1].first %> which when POSTed will give you an array of answer_names in params[:question][:answers], into which you can (re-)insert the correct_or_not data. -- We develop, watch us RoR, in numbers too big to ignore.
Excellent, Mark. Thank you. Steve On 3/15/06, Mark Reginald James <mrj@bigpond.net.au> wrote:> > Steve Odom wrote: > > I am using a serialized attribute in one of my models The serialized > > data is in the form of an array. I want to have a text_tag for each > > element contained in my serialized attribute. How would I construct the > > text_tag? > > > > My model name is ''questions''. The serialized attribute is "answers" > > > > So I might have: > > > > <% form tag %> > > <% text_tag ''question'', ''name'' %> > > <% text_tag ''question'', ''answers[0]'' %> > > <% text_tag ''question'', ''answers[1]'' %> > > > > It''s the last two I can''t figure out. I''m sure there is a clean, simple > > way of doing it. > > > > Slight complications - my stored array is actually an arrays within an > > array - storing the answer_name and correct_or_not. Some answers might > > have 2 answers, while others might have 5. > > <% form tag %> > <% text_field ''question'', ''name'' %> > <% text_field_tag ''question[answers][]'', @question.answers[0].first %> > <% text_field_tag ''question[answers][]'', @question.answers[1].first %> > > which when POSTed will give you an array of answer_names in > params[:question][:answers], into which you can (re-)insert > the correct_or_not data. > > > -- > We develop, watch us RoR, in numbers too big to ignore. > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060315/f3edebff/attachment.html
I spoke too soon. I''m getting this error message:
@question[answers_container]'' is not allowed as an instance variable
name
on the second line below:
---------
<%= text_area("question", "question_text", :cols=>41,
:rows=>3, :class =>
"question_input") %>
<%= text_field(''question[answers_container][]'',
@question.answers_container[0].first,
:size => 75, :class => "thin_borderGreen") %>
-------------
My model look like this:
=> #<Question:0x397c4e8 @attributes={"created_on"=>nil,
"answers_container"=>nil
, "updated_on"=>nil, "notes"=>nil,
"user_id"=>0, "ratings_count"=>0,
"active"=>"
0", "question_text"=>nil}, @new_record=true>
Any ideas?
Steve
http://www.smarkets.net
On 3/15/06, Mark Reginald James <mrj@bigpond.net.au>
wrote:>
> Steve Odom wrote:
> > I am using a serialized attribute in one of my models The serialized
> > data is in the form of an array. I want to have a text_tag for each
> > element contained in my serialized attribute. How would I construct
the
> > text_tag?
> >
> > My model name is ''questions''. The serialized
attribute is "answers"
> >
> > So I might have:
> >
> > <% form tag %>
> > <% text_tag ''question'', ''name''
%>
> > <% text_tag ''question'',
''answers[0]'' %>
> > <% text_tag ''question'',
''answers[1]'' %>
> >
> > It''s the last two I can''t figure out. I''m
sure there is a clean, simple
> > way of doing it.
> >
> > Slight complications - my stored array is actually an arrays within an
> > array - storing the answer_name and correct_or_not. Some answers might
> > have 2 answers, while others might have 5.
>
> <% form tag %>
> <% text_field ''question'', ''name''
%>
> <% text_field_tag ''question[answers][]'',
@question.answers[0].first %>
> <% text_field_tag ''question[answers][]'',
@question.answers[1].first %>
>
> which when POSTed will give you an array of answer_names in
> params[:question][:answers], into which you can (re-)insert
> the correct_or_not data.
>
>
> --
> We develop, watch us RoR, in numbers too big to ignore.
>
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://wrath.rubyonrails.org/pipermail/rails/attachments/20060315/630a5ce7/attachment.html
Julian Leviston
2006-Mar-15 23:05 UTC
[Rails] Re: Populating text_tag with serialized data
The format is text_field(object, method.... etc) so you need to put
text_field(''question'',
''answers_container[]'',...) similar to how you
did above it.
Julian.
On 16/03/2006, at 4:01 AM, Steve Odom wrote:
> I spoke too soon. I''m getting this error message:
>
> @question[answers_container]'' is not allowed as an instance
> variable nameon the second line below:
> ---------
> <%= text_area("question",
> "question_text", :cols=>41, :rows=>3, :class =>
"question_input") %>
>
> <%= text_field(''question[answers_container][]'',
> @question.answers_container[0].first, :size => 75, :class =>
> "thin_borderGreen") %>
> -------------
>
> My model look like this:
> => #<Question:0x397c4e8 @attributes={"created_on"=>nil,
> "answers_container"=>nil
> , "updated_on"=>nil, "notes"=>nil,
"user_id"=>0,
> "ratings_count"=>0, "active"=>"
> 0", "question_text"=>nil}, @new_record=true>
>
> Any ideas?
>
> Steve
> http://www.smarkets.net
>
>
>
>
> On 3/15/06, Mark Reginald James <mrj@bigpond.net.au> wrote:Steve
> Odom wrote:
> > I am using a serialized attribute in one of my models The serialized
> > data is in the form of an array. I want to have a text_tag for each
> > element contained in my serialized attribute. How would I
> construct the
> > text_tag?
> >
> > My model name is ''questions''. The serialized
attribute is "answers"
> >
> > So I might have:
> >
> > <% form tag %>
> > <% text_tag ''question'', ''name''
%>
> > <% text_tag ''question'',
''answers[0]'' %>
> > <% text_tag ''question'',
''answers[1]'' %>
> >
> > It''s the last two I can''t figure out. I''m
sure there is a clean,
> simple
> > way of doing it.
> >
> > Slight complications - my stored array is actually an arrays
> within an
> > array - storing the answer_name and correct_or_not. Some answers
> might
> > have 2 answers, while others might have 5.
>
> <% form tag %>
> <% text_field ''question'', ''name''
%>
> <% text_field_tag ''question[answers][]'',
@question.answers[0].first %>
> <% text_field_tag ''question[answers][]'',
@question.answers[1].first %>
>
> which when POSTed will give you an array of answer_names in
> params[:question][:answers], into which you can (re-)insert
> the correct_or_not data.
>
>
> --
> We develop, watch us RoR, in numbers too big to ignore.
>
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
Mark Reginald James
2006-Mar-15 23:29 UTC
[Rails] Re: Populating text_tag with serialized data
Steve Odom wrote:> I spoke too soon. I''m getting this error message: > > |@question[answers_container]'' is not allowed as an instance variable name| > > on the second line below: > --------- > <%= text_area("question", "question_text", :cols=>41, :rows=>3, :class > => "question_input") %> > > <%= text_field(''question[answers_container][]'', > @question.answers_container[0].first, :size => 75, :class => > "thin_borderGreen") %> > -------------Note that in my answer I used text_field_tag rather than text_field:> <%= text_field_tag ''question[answers][]'', @question.answers[0].first %>-- We develop, watch us RoR, in numbers too big to ignore.
Thanks to you both. The text_field_tag did it. I overlooked it previously. Aussies seem to really know the form_helper library. ; ) Steve http://www.smarkets.net On 3/15/06, Mark Reginald James <mrj@bigpond.net.au> wrote:> > Steve Odom wrote: > > I spoke too soon. I''m getting this error message: > > > > |@question[answers_container]'' is not allowed as an instance variable > name| > > > > on the second line below: > > --------- > > <%= text_area("question", "question_text", :cols=>41, :rows=>3, :class > > => "question_input") %> > > > > <%= text_field(''question[answers_container][]'', > > @question.answers_container[0].first, :size => 75, :class => > > "thin_borderGreen") %> > > ------------- > > Note that in my answer I used text_field_tag rather than text_field: > > > <%= text_field_tag ''question[answers][]'', @question.answers[0].first > %> > > -- > We develop, watch us RoR, in numbers too big to ignore. > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060316/af6bc8d6/attachment.html