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
<% @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| …?
I don’t know if is the best solution but try a cast with to_i in doc[“value”].
doc[“value”] .to_i
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.
<% @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.
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