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
El martes, 22 de mayo de 2012 15:29:04 UTC+2, amvis escribi:
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
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:
@update_coupon.each do |key, val|
//code related to key, such as:
<%= key%>
val.each do |update_coupon|
// code related to each update_coupon
end
end
On Tuesday, 22 May 2012 09:34:20 UTC-4, azizmb.in wrote:
problem, here in my code
<%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.
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
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.