Hello
am a newbie :)
am developing a portal for employees company. there is an edit form that
allows employees to change their information ( phone number, address,
etc)
here is the employees controller
def contact_information
current_user= session[:login]
@contact_information= Employee.find_by_sql( "select * from employees
where id='#{current_user}'")
end
in the form i have :
<% for obj in @contact_information%>
<table width="90%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="52%" height="160">
<table width="93%" border="0" cellspacing="0" cellpadding="0"
class="subtable">
<% form_tag :action => 'save_contact_information',
:employee=>@employee do %>
<tr >
<th height="28" colspan="2" >Work</th>
</tr>
<tr>
<td width="32%" height="22" >Work Location</td>
<td width="68%"><%= text_field 'employee', 'work_location'
,:maxlength => 50,:size=>25,:value=>obj.work_location %></td>
</tr>
<tr>
<td height="19" >Work State</td>
<td><%= text_field 'employee', 'work_state_id' ,:maxlength =>
50,:size=>25%></td>
</tr>
<tr>
<td height="19" >Work Phone</td>
<td><%= text_field 'employee', 'work_phone' ,:maxlength =>
50,:size=>25,:value=>obj.work_phone %></td>
</tr>
<tr>
<td height="19" >Mobile Phone</td>
<td><%= text_field 'employee', 'mobile_phone' ,:maxlength =>
50,:size=>25,:value=>obj.mobile_phone %></td>
</tr>
<tr>
<td height="19" >Work Fax</td>
<td><%= text_field 'employee', 'work_fax' ,:maxlength =>
50,:size=>25,:value=>obj.work_fax %></td>
</tr>
<tr>
<td height="19" >Work Email</td>
<td ><%= text_field 'employee', 'work_email' ,:maxlength =>
50,:size=>25,:value=>obj.work_email %></td>
</tr>
</table>
</td>
<td width="48%" rowspan="2" valign="top"> <table width="99%"
border="0" align="center" cellpadding="0" cellspacing="0"
class="subtable">
<tr>
<th height="28" colspan="2" > <legend>Permanent
Home</legend></th>
</tr>
<tr>
<td width="38%">Address 1</td>
<td width="62%"><%= text_field 'employee', 'street_address1'
,:maxlength => 50,:size=>25,:value=>obj.street_address1 %></td>
</tr>
<tr>
<td>Address 2</td>
<td><%= text_field 'employee', 'street_address2' ,:maxlength
=> 50,:size=>25,:value=>obj.street_address2 %></td>
</tr>
<tr>
<td>City</td>
<td><%= text_field 'employee', 'city' ,:maxlength =>
50,:size=>25,:value=>obj.city%></td>
</tr>
<tr>
<td>State</td>
<td><%= select 'employee','state_id', State.find(:all).collect
{|c| [c.state_name, c.id]},{:selected=>obj.state_id}%></td>
</tr>
<tr>
<td>Postal code</td>
<td><%= text_field 'employee', 'postal_code' ,:maxlength =>
50,:size=>25,:value=>obj.postal_code%></td>
</tr>
<tr>
<td>Country</td>
<td><%= country_select 'employee', 'country' %></td>
</tr>
<tr>
<td>Home Phone </td>
<td><%= text_field 'employee', 'home_phone' ,:maxlength =>
50,:size=>25,:value=>obj.home_phone%></td>
</tr>
</table></td>
</tr>
<tr>
<td height="142">
<table width="93%" border="0" cellpadding="0" cellspacing="0"
class="subtable">
<tr>
<th height="28" colspan="2">Current Home</th>
</tr>
<tr>
<td width="43%">Address 1</td>
<td width="57%"><%= text_field 'employee',
'present_street_address1' ,:maxlength =>
50,:size=>25,:value=>obj.present_street_address1 %></td>
</tr>
<tr>
<td>Address 2</td>
<td><%= text_field 'employee', 'present_street_address2'
,:maxlength => 50,:size=>25,:value=>obj.present_street_address2 %></td>
</tr>
<tr>
<td>city</td>
<td><%= text_field 'employee', 'present_city' ,:maxlength =>
50,:size=>25,:value=>obj.present_city%></td>
</tr>
<tr>
<td>State</td>
<td><%= select 'employee','present_state_id',
State.find(:all).collect {|c| [c.state_name,
c.id]},{:selected=>obj.present_state_id}%></td>
</tr>
<tr>
<td>Postal code</td>
<td><%= text_field 'employee', 'present_postal_code'
,:maxlength => 50,:size=>25,:value=>obj.present_postal_code%></td>
</tr>
<tr>
<td>Country</td>
<td><%= country_select 'employee', 'present_country' %></td>
</tr>
<tr>
<td>Mobile Phone</td>
<td><%= text_field 'employee', 'mobile_phone' ,:maxlength =>
50,:size=>25,:value=>obj.mobile_phone%></td>
</tr>
<tr>
<td>Personal Email</td>
<td><%= text_field 'employee', 'personal_email' ,:maxlength
=> 50,:size=>25,:value=>obj.personal_email%></td>
</tr>
</table></td>
</tr>
<tr align="center" valign="middle">
<td colspan="2"><%= submit_tag "Save all changes"%></td>
</tr>
</table>
<%end%>
<%end%>
the problem is when an employee open this page, countrie_selct always
shows the first country ( Afghanistan) while it should show something
else ( India for example), as well as for states.
any help will be much appreciated
Thank you
Feras,
on 27.05.2008 21:17