*controller* @update_coupon = JSON.parse(get_updatecpn.body) * * *view* 1, <% @update_coupon.each do |doc| %> 2, <% if doc["value"] == 2 %> 3, <%end%> Here the *@update_coupon* getting from controller,In the controller i got all the value from *@update_coupon* so i need to take the value from this* @update_coupon* in view. so when i am trying to take the value from the @update_coupon, it gives an error *can''t convert string to integer* in line 2 have any other way to do this view? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/xnmAl4-br4IJ. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
I don''t know if is the best solution but try a cast with to_i in doc["value"]. doc["value"] .to_i On Tue, May 22, 2012 at 10:29 AM, amvis <vgrkrishnan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> *controller* > @update_coupon = JSON.parse(get_updatecpn.body) > * > * > *view* > 1, <% @update_coupon.each do |doc| %> > 2, <% if doc["value"] == 2 %> > > 3, <%end%> > > Here the *@update_coupon* getting from controller,In the controller i got > all the value from *@update_coupon* so i need to take the value from this* > @update_coupon* in view. so when i am trying to take the value from > the @update_coupon, it gives an error *can''t convert string to integer* in > line 2 > > have any other way to do this view? > > > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To view this discussion on the web visit > https://groups.google.com/d/msg/rubyonrails-talk/-/xnmAl4-br4IJ. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. >-- Atenciosamente, Guilherme Pereira Dutra, Fone: (34) 8407-0109 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Also, you could clean things a little by doing: <% @update_coupon.select{|doc| doc["value"] == 2}.each do |doc| %> do stuff <% end %> On Tue, May 22, 2012 at 7:02 PM, Guilherme Dutra <guipereira07-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote:> I don''t know if is the best solution but try a cast with to_i in > doc["value"]. > > doc["value"] .to_i > > > On Tue, May 22, 2012 at 10:29 AM, amvis <vgrkrishnan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> *controller* >> @update_coupon = JSON.parse(get_updatecpn.body) >> * >> * >> *view* >> 1, <% @update_coupon.each do |doc| %> >> 2, <% if doc["value"] == 2 %> >> >> 3, <%end%> >> >> Here the *@update_coupon* getting from controller,In the controller i >> got all the value from *@update_coupon* so i need to take the value from >> this* @update_coupon* in view. so when i am trying to take the value >> from the @update_coupon, it gives an error *can''t convert string to >> integer* in line 2 >> >> have any other way to do this view? >> >> >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Ruby on Rails: Talk" group. >> To view this discussion on the web visit >> https://groups.google.com/d/msg/rubyonrails-talk/-/xnmAl4-br4IJ. >> To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> To unsubscribe from this group, send email to >> rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> For more options, visit this group at >> http://groups.google.com/group/rubyonrails-talk?hl=en. >> > > > > -- > Atenciosamente, > Guilherme Pereira Dutra, > Fone: (34) 8407-0109 > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. >-- - Aziz M. Bookwala Website <http://azizmb.in/> | Twitter <https://twitter.com/azizbookwala> | Github <http://github.com/azizmb> -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
El martes, 22 de mayo de 2012 15:29:04 UTC+2, amvis escribió:> > *controller* > @update_coupon = JSON.parse(get_updatecpn.body) > * > * > *view* > 1, <% @update_coupon.each do |doc| %> > 2, <% if doc["value"] == 2 %> > > 3, <%end%> > > Here the *@update_coupon* getting from controller,In the controller i got > all the value from *@update_coupon* so i need to take the value from this* > @update_coupon* in view. so when i am trying to take the value from > the @update_coupon, it gives an error *can''t convert string to integer* in > line 2 > > have any other way to do this view? > > > Your condition should be one of these:* doc["value"] == "2" / doc["value"].eql?("2") * doc["value"].to_i == 2 / doc["value"].to_i.eql?(2) Alternatively you might as well iterate through already selected items: @update_coupon.select{ |q| q["value].eql?(''2'') }each do |doc| ... There are lots of ways of doing this to find your favourite.>-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/Hb6baHHOqhQJ. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Tuesday, 22 May 2012 09:34:20 UTC-4, azizmb.in wrote:> > Also, you could clean things a little by doing: > > <% @update_coupon.select{|doc| doc["value"] == 2}.each do |doc| %> > do stuff > <% end %> > >Thanks all i think the above one is working, but i am confused with other problem, here in my code <% @update_coupon.each do |doc| %> <% if doc["value"] == 2 %> //code <%elsif doc["value"] == 5 %> //code <%elsif doc["value"] == 6 %> //code <%end%> <%end%> so how to integrate with this @update_coupon.select{|doc| doc["value"] == 2}.each do |doc| .......?> > On Tue, May 22, 2012 at 7:02 PM, Guilherme Dutra <guipereira07-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote: > >> I don''t know if is the best solution but try a cast with to_i in >> doc["value"]. >> >> doc["value"] .to_i >> >> >> On Tue, May 22, 2012 at 10:29 AM, amvis <vgrkrishnan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >>> *controller* >>> @update_coupon = JSON.parse(get_updatecpn.body) >>> * >>> * >>> *view* >>> 1, <% @update_coupon.each do |doc| %> >>> 2, <% if doc["value"] == 2 %> >>> >>> 3, <%end%> >>> >>> Here the *@update_coupon* getting from controller,In the controller i >>> got all the value from *@update_coupon* so i need to take the value >>> from this* @update_coupon* in view. so when i am trying to take the >>> value from the @update_coupon, it gives an error *can''t convert string >>> to integer* in line 2 >>> >>> have any other way to do this view? >>> >>> >>> >>> -- >>> You received this message because you are subscribed to the Google >>> Groups "Ruby on Rails: Talk" group. >>> To view this discussion on the web visit >>> https://groups.google.com/d/msg/rubyonrails-talk/-/xnmAl4-br4IJ. >>> To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >>> To unsubscribe from this group, send email to >>> rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >>> For more options, visit this group at >>> http://groups.google.com/group/rubyonrails-talk?hl=en. >>> >> >> >> >> -- >> Atenciosamente, >> Guilherme Pereira Dutra, >> Fone: (34) 8407-0109 >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Ruby on Rails: Talk" group. >> To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> To unsubscribe from this group, send email to >> rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> For more options, visit this group at >> http://groups.google.com/group/rubyonrails-talk?hl=en. >> > > > > -- > - Aziz M. Bookwala > > Website <http://azizmb.in/> | Twitter <https://twitter.com/azizbookwala> > | Github <http://github.com/azizmb> > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/E0yE1thyXmoJ. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
El martes, 22 de mayo de 2012 15:56:54 UTC+2, amvis escribió:> > > > On Tuesday, 22 May 2012 09:34:20 UTC-4, azizmb.in wrote: >> >> Also, you could clean things a little by doing: >> >> <% @update_coupon.select{|doc| doc["value"] == 2}.each do |doc| %> >> do stuff >> <% end %> >> >> > Thanks all > i think the above one is working, but i am confused with other > problem, here in my code > > <% @update_coupon.each do |doc| %> > <% if doc["value"] == 2 %> > //code > <%elsif doc["value"] == 5 %> > //code > <%elsif doc["value"] == 6 %> > //code > <%end%> > > <%end%> > > so how to integrate with this @update_coupon.select{|doc| doc["value"] == > 2}.each do |doc| .......? > > > >> >> On Tue, May 22, 2012 at 7:02 PM, Guilherme Dutra <guipereira07-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote: >> >>> I don''t know if is the best solution but try a cast with to_i in >>> doc["value"]. >>> >>> doc["value"] .to_i >>> >>> >>> On Tue, May 22, 2012 at 10:29 AM, amvis <vgrkrishnan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >>> >>>> *controller* >>>> @update_coupon = JSON.parse(get_updatecpn.body) >>>> * >>>> * >>>> *view* >>>> 1, <% @update_coupon.each do |doc| %> >>>> 2, <% if doc["value"] == 2 %> >>>> >>>> 3, <%end%> >>>> >>>> Here the *@update_coupon* getting from controller,In the controller i >>>> got all the value from *@update_coupon* so i need to take the value >>>> from this* @update_coupon* in view. so when i am trying to take the >>>> value from the @update_coupon, it gives an error *can''t convert string >>>> to integer* in line 2 >>>> >>>> have any other way to do this view? >>>> >>>> >>>> >>>> -- >>>> You received this message because you are subscribed to the Google >>>> Groups "Ruby on Rails: Talk" group. >>>> To view this discussion on the web visit >>>> https://groups.google.com/d/msg/rubyonrails-talk/-/xnmAl4-br4IJ. >>>> To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org. >>>> To unsubscribe from this group, send email to >>>> rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >>>> For more options, visit this group at >>>> http://groups.google.com/group/rubyonrails-talk?hl=en. >>>> >>> >>> >>> >>> -- >>> Atenciosamente, >>> Guilherme Pereira Dutra, >>> Fone: (34) 8407-0109 >>> >>> -- >>> You received this message because you are subscribed to the Google >>> Groups "Ruby on Rails: Talk" group. >>> To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >>> To unsubscribe from this group, send email to >>> rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >>> For more options, visit this group at >>> http://groups.google.com/group/rubyonrails-talk?hl=en. >>> >> >> >> >> -- >> - Aziz M. Bookwala >> >> Website <http://azizmb.in/> | Twitter <https://twitter.com/azizbookwala> >> | Github <http://github.com/azizmb> >> >>What are you trying to achieve with that, exactly? Looks like grouping to me, in which case you might do in your controller: @update_coupon = @update_coupon.group_by(&:value) Assuming @update_coupon is an array of a class having a value attribute, that would return a hash much alike: { 2 => [UC1, UC2....], 5 => [UC3, UC4...], ... } Once in your view you might iterate as follows: <pre> @update_coupon.each do |key, val| //code related to key, such as: <h2><%= key%></h2> val.each do |update_coupon| // code related to each update_coupon end end </pre> -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/WQmUhl3LYYoJ. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Tuesday, 22 May 2012 10:23:53 UTC-4, Juan Pablo Avello wrote:> > > > El martes, 22 de mayo de 2012 15:56:54 UTC+2, amvis escribió: >> >> >> >> On Tuesday, 22 May 2012 09:34:20 UTC-4, azizmb.in wrote: >>> >>> Also, you could clean things a little by doing: >>> >>> <% @update_coupon.select{|doc| doc["value"] == 2}.each do |doc| %> >>> do stuff >>> <% end %> >>> >>> >> Thanks all >> i think the above one is working, but i am confused with other >> problem, here in my code >> >> <% @update_coupon.each do |doc| %> >> <% if doc["value"] == 2 %> >> //code >> <%elsif doc["value"] == 5 %> >> //code >> <%elsif doc["value"] == 6 %> >> //code >> <%end%> >> >> <%end%> >> >> so how to integrate with this @update_coupon.select{|doc| doc["value"] == >> 2}.each do |doc| .......? >> >> >> >>> >>> On Tue, May 22, 2012 at 7:02 PM, Guilherme Dutra <guipereira07-Re5JQEeQqe8@public.gmane.orgm >>> > wrote: >>> >>>> I don''t know if is the best solution but try a cast with to_i in >>>> doc["value"]. >>>> >>>> doc["value"] .to_i >>>> >>>> >>>> On Tue, May 22, 2012 at 10:29 AM, amvis <vgrkrishnan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >>>> >>>>> *controller* >>>>> @update_coupon = JSON.parse(get_updatecpn.body) >>>>> * >>>>> * >>>>> *view* >>>>> 1, <% @update_coupon.each do |doc| %> >>>>> 2, <% if doc["value"] == 2 %> >>>>> >>>>> 3, <%end%> >>>>> >>>>> Here the *@update_coupon* getting from controller,In the controller i >>>>> got all the value from *@update_coupon* so i need to take the value >>>>> from this* @update_coupon* in view. so when i am trying to take the >>>>> value from the @update_coupon, it gives an error *can''t convert >>>>> string to integer* in line 2 >>>>> >>>>> have any other way to do this view? >>>>> >>>>> >>>>> >>>>> -- >>>>> You received this message because you are subscribed to the Google >>>>> Groups "Ruby on Rails: Talk" group. >>>>> To view this discussion on the web visit >>>>> https://groups.google.com/d/msg/rubyonrails-talk/-/xnmAl4-br4IJ. >>>>> To post to this group, send email to rubyonrails-talk-/JYPxA39Uh4Ykp1iOSErHA@public.gmane.orgm >>>>> . >>>>> To unsubscribe from this group, send email to >>>>> rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >>>>> For more options, visit this group at >>>>> http://groups.google.com/group/rubyonrails-talk?hl=en. >>>>> >>>> >>>> >>>> >>>> -- >>>> Atenciosamente, >>>> Guilherme Pereira Dutra, >>>> Fone: (34) 8407-0109 >>>> >>>> -- >>>> You received this message because you are subscribed to the Google >>>> Groups "Ruby on Rails: Talk" group. >>>> To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org. >>>> To unsubscribe from this group, send email to >>>> rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >>>> For more options, visit this group at >>>> http://groups.google.com/group/rubyonrails-talk?hl=en. >>>> >>> >>> >>> >>> -- >>> - Aziz M. Bookwala >>> >>> Website <http://azizmb.in/> | Twitter <https://twitter.com/azizbookwala> >>> | Github <http://github.com/azizmb> >>> >>> > What are you trying to achieve with that, exactly? Looks like grouping to > me, in which case you might do in your controller: > > @update_coupon = @update_coupon.group_by(&:value) > >basically with that if condition, i need to show different div, <% @update_coupon.each do |doc| %> <% if doc["value"] == 2 %> //code <%elsif doc["value"] == 5 %> //code <%elsif doc["value"] == 6 %> //code <%end%> <%end%>> Assuming @update_coupon is an array of a class having a value attribute, > that would return a hash much alike: > { > 2 => [UC1, UC2....], > 5 => [UC3, UC4...], > ... > } > > Once in your view you might iterate as follows: > <pre> > @update_coupon.each do |key, val| > //code related to key, such as: <h2><%= key%></h2> > val.each do |update_coupon| > // code related to each update_coupon > end > end > </pre> > > > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/zYGz_lHMVYUJ. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 22 May 2012 15:36, amvis <vgrkrishnan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> basically with that if condition, i need to show different div, > > <% @update_coupon.each do |doc| %> > <% if doc["value"] == 2 %> > //code > <%elsif doc["value"] == 5 %> > //code > <%elsif doc["value"] == 6 %> > //code > <%end%> > > <%end%>You need a "case" statement as a starting point: http://stackoverflow.com/questions/948135/how-to-write-a-switch-statement-in-ruby -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 22 May 2012 15:36, amvis <vgrkrishnan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > On Tuesday, 22 May 2012 10:23:53 UTC-4, Juan Pablo Avello wrote: >> >> >> >> El martes, 22 de mayo de 2012 15:56:54 UTC+2, amvis escribió: >>> >>> >>> >>> On Tuesday, 22 May 2012 09:34:20 UTC-4, azizmb.in wrote: >>>> >>>> Also, you could clean things a little by doing: >>>> >>>> <% @update_coupon.select{|doc| doc["value"] == 2}.each do |doc| %> >>>> do stuff >>>> <% end %> >>>> >>>> >>> Thanks all >>> i think the above one is working, but i am confused with other >>> problem, here in my code >>> >>> <% @update_coupon.each do |doc| %> >>> <% if doc["value"] == 2 %> >>> //code >>> <%elsif doc["value"] == 5 %> >>> //code >>> <%elsif doc["value"] == 6 %> >>> //code >>> <%end%> >>> >>> <%end%> >>> >>You also want to be using a helper method here, maybe rendering a different partial depending on the value. When you start seeing this much logic in your view code, it''s probably wise to look at helpers and partials.> >>> so how to integrate with this @update_coupon.select{|**doc| >>> doc["value"] == 2}.each do |doc| .......? >>> >>> >>> >>>> >>>> On Tue, May 22, 2012 at 7:02 PM, Guilherme Dutra < >>>> guipereira07-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >>>> >>>>> I don''t know if is the best solution but try a cast with to_i in >>>>> doc["value"]. >>>>> >>>>> doc["value"] .to_i >>>>> >>>>> >>>>> On Tue, May 22, 2012 at 10:29 AM, amvis <vgrkrishnan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >>>>> >>>>>> *controller* >>>>>> @update_coupon = JSON.parse(get_updatecpn.body) >>>>>> * >>>>>> * >>>>>> *view* >>>>>> 1, <% @update_coupon.each do |doc| %> >>>>>> 2, <% if doc["value"] == 2 %> >>>>>> >>>>>> 3, <%end%> >>>>>> >>>>>> Here the *@update_coupon* getting from controller,In the controller >>>>>> i got all the value from *@update_coupon* so i need to take the >>>>>> value from this* @update_coupon* in view. so when i am trying to >>>>>> take the value from the @update_coupon, it gives an error *can''t >>>>>> convert string to integer* in line 2 >>>>>> >>>>>> have any other way to do this view? >>>>>> >>>>>> >>>>>> >>>>>> -- >>>>>> You received this message because you are subscribed to the Google >>>>>> Groups "Ruby on Rails: Talk" group. >>>>>> To view this discussion on the web visit https://groups.google.com/d/ >>>>>> **msg/rubyonrails-talk/-/xnmAl4-**br4IJ<https://groups.google.com/d/msg/rubyonrails-talk/-/xnmAl4-br4IJ> >>>>>> . >>>>>> To post to this group, send email to rubyonrails-talk@googlegroups.** >>>>>> com <rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>. >>>>>> To unsubscribe from this group, send email to >>>>>> rubyonrails-talk+unsubscribe@**googlegroups.com<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> >>>>>> . >>>>>> For more options, visit this group at http://groups.google.com/** >>>>>> group/rubyonrails-talk?hl=en<http://groups.google.com/group/rubyonrails-talk?hl=en> >>>>>> . >>>>>> >>>>> >>>>> >>>>> >>>>> -- >>>>> Atenciosamente, >>>>> Guilherme Pereira Dutra, >>>>> Fone: (34) 8407-0109 >>>>> >>>>> -- >>>>> You received this message because you are subscribed to the Google >>>>> Groups "Ruby on Rails: Talk" group. >>>>> To post to this group, send email to rubyonrails-talk@googlegroups.** >>>>> com <rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>. >>>>> To unsubscribe from this group, send email to >>>>> rubyonrails-talk+unsubscribe@**googlegroups.com<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> >>>>> . >>>>> For more options, visit this group at http://groups.google.com/** >>>>> group/rubyonrails-talk?hl=en<http://groups.google.com/group/rubyonrails-talk?hl=en> >>>>> . >>>>> >>>> >>>> >>>> >>>> -- >>>> - Aziz M. Bookwala >>>> >>>> Website <http://azizmb.in/> | Twitter<https://twitter.com/azizbookwala> >>>> | Github <http://github.com/azizmb> >>>> >>>> >> What are you trying to achieve with that, exactly? Looks like grouping to >> me, in which case you might do in your controller: >> >> @update_coupon = @update_coupon.group_by(&:**value) >> >> > basically with that if condition, i need to show different div, > > <% @update_coupon.each do |doc| %> > <% if doc["value"] == 2 %> > //code > <%elsif doc["value"] == 5 %> > //code > <%elsif doc["value"] == 6 %> > //code > <%end%> > > <%end%> > > > >> Assuming @update_coupon is an array of a class having a value attribute, >> that would return a hash much alike: >> { >> 2 => [UC1, UC2....], >> 5 => [UC3, UC4...], >> ... >> } >> >> Once in your view you might iterate as follows: >> <pre> >> @update_coupon.each do |key, val| >> //code related to key, such as: <h2><%= key%></h2> >> val.each do |update_coupon| >> // code related to each update_coupon >> end >> end >> </pre> >> >> >> >> -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To view this discussion on the web visit > https://groups.google.com/d/msg/rubyonrails-talk/-/zYGz_lHMVYUJ. > > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
I would still iterate the elements that way, then you may extract the div construction to several partials or a helper receiving the key and value that deals with what to render on each case. It may sound a bit complex, but this way you keep your views clean, which are 90% of the times the dirtiest part of an app by far, and future changes are faster to perform if you reuse that code somewhere else -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/mzuxoSGH8dEJ. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.