controls repeating in ruby on rails -


on signup page make communication preferences each user, means how other person contact person e.g: "phone","email","skype" , on settings page getting communication in text_field. if user have 3 communication i.e "phone","email","skype". show me below:

phone:   [1234567895] email:   [abc@ab.com] skype:   [abc       ] 

assume square brackets "[ ]" text_field show me below:

phone:   [1234567895] email:   [          ] skype:   [          ] phone:   [          ] email:   [abc@ab.com] skype:   [          ] phone:   [          ] email:   [          ] skype:   [abc       ] 

and below new .html.erb of setings page:

   <table>     <% if @user_communication.blank? %>          <tr style="text-align: left; vertical-align: middle;">          <td style="font-size: large; color: #212121;">              phone:          </td>          <td style="font-size: large; color: #212121;">              <%= text_field :tf_phone, placeholder: 'phone' %>           </td>       </tr>       <tr style="text-align: left; vertical-align: middle;">          <td style="font-size: large; color: #212121;">             email:          </td>          <td style="font-size: large; color: #212121;">              <%= text_field :tf_email, placeholder: 'email' %>           </td>       </tr>       <tr style="text-align: left; vertical-align: middle;">          <td style="font-size: large; color: #212121;">             skype:          </td>          <td style="font-size: large; color: #212121;">              <%= text_field :tf_skype, placeholder: 'skype' %>           </td>       </tr>       <tr style="text-align: left; vertical-align: middle;">          <td style="font-size: large; color: #212121;">             website:          </td>          <td style="font-size: large; color: #212121;">              <%= text_field :tf_website, placeholder: 'website' %>           </td>       </tr>       <tr style="text-align: left; vertical-align: middle;">          <td style="font-size: large; color: #212121;">             twitter:          </td>          <td style="font-size: large; color: #212121;">              <%= text_field :tf_twitter, placeholder: 'twitter'  %>          </td>       </tr>     <%else %>     <% @user_communication.each |user_com| %>     <tr style="text-align: left; vertical-align: middle;">          <td style="font-size: large; color: #212121;">             phone:          </td>          <td style="font-size: large; color: #212121;">             <% if user_com.communicationmode.to_s == "phone" %>             <%= text_field_tag :tf_phone, user_com.communicationdetail %>             <% else %>             <%= text_field :tf_phone, :placeholder => "phone" %>             <% end %>          </td>       </tr>       <tr style="text-align: left; vertical-align: middle;">          <td style="font-size: large; color: #212121;">             email:          </td>          <td style="font-size: large; color: #212121;">             <% if user_com.communicationmode.to_s == "email" %>             <%= text_field_tag :tf_email, user_com.communicationdetail %>             <% else %>             <%= text_field :tf_email,:placeholder => "email" %>             <% end %>          </td>       </tr>       <tr style="text-align: left; vertical-align: middle;">          <td style="font-size: large; color: #212121;">             skype:          </td>          <td style="font-size: large; color: #212121;">             <% if user_com.communicationmode.to_s == "skype" %>             <%= text_field_tag :tf_skype, user_com.communicationdetail %>             <% else %>             <%= text_field :tf_skype,:placeholder => "skype" %>             <% end %>          </td>       </tr>       <tr style="text-align: left; vertical-align: middle;">          <td style="font-size: large; color: #212121;">             website:          </td>          <td style="font-size: large; color: #212121;">             <% if user_com.communicationmode.to_s == "website" %>             <%= text_field_tag :tf_website, user_com.communicationdetail %>             <% else %>             <%= text_field :tf_website,:placeholder => "website" %>             <% end %>          </td>       </tr>       <tr style="text-align: left; vertical-align: middle;">          <td style="font-size: large; color: #212121;">             twitter:          </td>          <td style="font-size: large; color: #212121;">             <% if user_com.communicationmode.to_s == "twitter" %>             <%= text_field_tag :tf_twitter, user_com.communicationdetail%>             <% else %>             <%= text_field :tf_twitter, :placeholder => "twitter" %>             <% end %>          </td>       </tr>     <% end %>     <%end %> </table> 

kindly suggest me make mistake, waiting reply. thanks.

the problem code you're looping through @user_communication , inside loop, you're showing communications. remove loop , change code following

<tr style="text-align: left; vertical-align: middle;">   <td style="font-size: large; color: #212121;">     phone:   </td>   <td style="font-size: large; color: #212121;">     <% phone = @user_communication.detect { |uc| uc.communicationmode.to_s == 'phone' } %>     <% if phone %>       <%= text_field_tag :tf_phone, user_com.communicationdetail %>     <% else %>       <%= text_field :tf_phone, :placeholder => "phone" %>     <% end %>   </td> </tr> 

then repeat each communication. remember, don't place code inside loop.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -