Ruby on Rails Thursday, January 26, 2012

controller
----------

your erb like this way:

----------------------------------------------------------------------
user_name | email | street | city | state |
----------------------------------------------------------------------
user1 | abc@gmail.com | x | xx | TN |
----------------------------------------------------------------------
user2 | cde@gmail.com | y | yy | KL |
----------------------------------------------------------------------

use table structure:

the first row is header:
the second row is td

form like this way

<table>
<tr>
<td>user_name</td>
<td>email</td>
<td>street</td>
<td>city</td>
<td>state</td>
</tr>
<%= form_tag "action" ,:mode=>"update",:multipart => true do %>
<% for i in 0..1%>
<%= text_field_tag :"user_name_#{i}",""%>
<%= text_field_tag :"email_#{i}",""%>
<%= text_field_tag :"street_#{i}",""%>
<%= text_field_tag :"city_#{i}",""%>
<%= text_field_tag :"state_#{i}",""%>
<% end%>
<%= submit_tag "update" %>
<%end%>
</table>

controller file:

if params[:mode]=="update"
count = 0
loop{
user_name = "user_name_"+count.to_s
email = "email_"+count.to_s
street = "street_"+count.to_s
city = "city_"+count.to_s
state = "state_"+count.to_s

if !params[user_name].blank?
User.create(
:user_name => params[user_name],
:email => params[user_name],
:street => params[user_name],
:city => params[user_name],
:state => params[user_name]
)
end

count = count + 1
user_name = "user_name_"+count.to_s
break if params[user_name].blank?

}
end

bye:)
bdeveloper01

--
Posted via http://www.ruby-forum.com/.

--
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.
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.

No comments:

Post a Comment