I''m trying to do: <% for item in @items %> ... <%= text_field(''item[]'', ''title'') %> <%= check_box(''item[]'', ''active'') %> ... <% end %> Possible? I get a nil object error. thanks csn __________________________________ Yahoo! Music Unlimited Access over 1 million songs. Try it free. http://music.yahoo.com/unlimited/
try: <% for item in @items %> ... <%= text_field(item, title) %> <%= check_box(item, active) %> ... <% end %> On 11/23/05, CSN <cool_screen_name90001-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> wrote:> > I''m trying to do: > > <% for item in @items %> > ... > <%= text_field(''item[]'', ''title'') %> > <%= check_box(''item[]'', ''active'') %> > ... > <% end %> > > Possible? I get a nil object error. > > thanks > csn > > > > __________________________________ > Yahoo! Music Unlimited > Access over 1 million songs. Try it free. > http://music.yahoo.com/unlimited/ > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Results: <%= text_field(item, title) %> undefined local variable or method `title'' for #<#<Class:0x40757350>:0x40757288> <%= text_field(item, ''title'') %> `@#<Item:0x4099796c>'' is not allowed as an instance variable name csn --- Chris Hall <christopher.k.hall-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> try: > > <% for item in @items %> > ... > <%= text_field(item, title) %> > <%= check_box(item, active) %> > ... > <% end %> > > On 11/23/05, CSN <cool_screen_name90001-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> wrote: > > > > I''m trying to do: > > > > <% for item in @items %> > > ... > > <%= text_field(''item[]'', ''title'') %> > > <%= check_box(''item[]'', ''active'') %> > > ... > > <% end %> > > > > Possible? I get a nil object error. > > > > thanks > > csn > > > > > > > > __________________________________ > > Yahoo! Music Unlimited > > Access over 1 million songs. Try it free. > > http://music.yahoo.com/unlimited/ > > _______________________________________________ > > Rails mailing list > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >__________________________________ Yahoo! Music Unlimited Access over 1 million songs. Try it free. http://music.yahoo.com/unlimited/
> <% for item in @items %> > ... > <%= text_field(''item[]'', ''title'') %> > <%= check_box(''item[]'', ''active'') %> > ... > <% end %> > > Possible? I get a nil object error.i do something similar in an application, sorry for not replacing the instant variable names with something more generic, but i''m sure you will get the idea. <% for @question in @course.questions -%> <%= text_field("question[]", ''question'' -%><br/> <% for @answer in @question.answers -%> <%= text_field("answer[]", ''answer'', -%><br/> <%= check_box("answer[]", ''correct'', -%><br/> <% end -%> <% end -%> hope that helps. wait. it looks like this is what you are trying to do... if so, just make sure that you have something in @items. -ian -- Posted via http://www.ruby-forum.com/.
Is there any reason why a for loop is preferable to an each iterator? From what I''ve seen ruby prefers the iterator approach. Is this correct or have I misunderstood? I don''t know where I''ve got this impression from, but I would like to know which is better. Cheers On 11/24/05, ian kennedy <exposure-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > <% for item in @items %> > > ... > > <%= text_field(''item[]'', ''title'') %> > > <%= check_box(''item[]'', ''active'') %> > > ... > > <% end %> > > > > Possible? I get a nil object error. > > i do something similar in an application, sorry for not replacing the > instant variable names with something more generic, but i''m sure you > will get the idea. > > <% for @question in @course.questions -%> > <%= text_field("question[]", ''question'' -%><br/> > <% for @answer in @question.answers -%> > <%= text_field("answer[]", ''answer'', -%><br/> > <%= check_box("answer[]", ''correct'', -%><br/> > <% end -%> > <% end -%> > > hope that helps. > > wait. it looks like this is what you are trying to do... if so, just > make sure that you have something in @items. > > -ian > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Liquid wrote:> Is there any reason why a for loop is preferable to an each iterator? > From what I''ve seen ruby prefers the iterator approach. Is this > correct or have I misunderstood? I don''t know where I''ve got this > impression from, but I would like to know which is better. >As far as I know, for v in values ... end is identical to values.each do |v| ...end I prefer the internal iterator approach, for loops in ruby seem to be nothing more than syntactic sugar and sugar is bad for you ;) Kev
> As far as I know, > for v in values ... end > > is identical to > > values.each do |v| ...end > > I prefer the internal iterator approach, for loops in ruby seem to be > nothing more than syntactic sugar and sugar is bad for you ;) >yep. i could just have easily done this: <% @course.questions.each do |q| -%> <%= text_field("question[]", ''question'' -%><br/> <% @question.answers.each do |a| -%> <%= text_field("answer[]", ''answer'', -%><br/> <%= check_box("answer[]", ''correct'', -%><br/> <% end -%> <% end -%> ian -- Posted via http://www.ruby-forum.com/.