Hello everybody i’m new working with rails.
I want to creata new relation in my app but it fail. This is the code:
model profile.rb
class Profile < ActiveRecord::Base
has_many :responsibles
end
model reponsible.rb
class Responsible < ActiveRecord::Base
belongs_to :profile, :class_name => ‘Profile’, :foreign_key =>
‘profile_id’
end
in the controller responsibles_controller.rb
class Member::ResponsiblesController < Member::BaseController
def create
@responsibles =
current_user.responsibles.build(params[:responsible].values)
@responsible.save!
flash[:ok] = I18n.t("tog_picto.member.responsibles_created")
redirect_to profile_path(profile)
end
def update
responsible.update_attributes!(params[:responsibles])
responsible.save
flash[:ok] =
I18n.t(“tog_social.profiles.member.responsibles_created”)
redirect_to profile_path(profile)
end
end
and in the view to edit the profile i want to add if it’s possible
update the responsibles:
<%= error_messages_for :profile %>
<% form_for :profile, :url => member_profile_path(@profile), :html =>
{:method => :put, :multipart=>true} do |f| -%>
<%= I18n.t(‘tog_social.profiles.member.profile_details’)
%>
<%=
I18n.t(‘tog_social.profiles.model.first_name’) %>
<%= f.text_field :first_name, :class=>“fieldbox” %>
<%=
I18n.t(‘tog_social.profiles.model.last_name’) %>
<%= f.text_field :last_name, :class=>“fieldbox” %>
<p>
<label for="profile_situation"><%=
I18n.t(‘tog_social.profiles.model.situation’) %>
<%= I18n.t(“tog_social.profiles.model.select_situation”)
%>
Activo
Desempleado
Estudiante
Jubilado
<p>
<%= check_box_tag 'profile_demandante_de_empleo'%>
<label for="profile_demandante_de_empleo">
<%= I18n.t('tog_social.profiles.model.demandante_de_empleo') %>
</label>
</p>
<p>
<label for="profile_profession"><%=
I18n.t(‘tog_social.profiles.model.profession’) %>
<%= f.text_field :profession, :class=>“fieldbox” %>
<!--Lugar del usuario-->
<p>
<label for="profile_place"><%=
I18n.t(‘tog_social.profiles.model.place’) %>
<%= I18n.t(“tog_social.profiles.model.select_place”) %>
lava
Albacete
Alicante
Almera
Asturias
vila
Badajoz
Barcelona
Burgos
Cceres
Cdiz
Cantabria
Castelln
Ciudad Real
Crdoba
Cuenca
Gerona
Granada
Guadalajara
Guipzcua
Huelva
Huesca
Islas Baleares
Jan
La Corua
Las Palmas
Len
Lrida
Lugo
Madrid
Mlaga
Murcia
Navarra
Orense
Palencia
Las Palmas
Pontevedra
La Rioja
Salamanca
Segovia
Sevilla
Soria
Tarragona
Santa Cruz de Tenerife</
option>
Teruel
Toledo
Valencia
Valladolid
Vizcaya
Zamora
Zaragoza
<!--email del Usuario-->
<p>
<label for="profile_contact_email"><%=
I18n.t(‘tog_social.profiles.model.contact_email’) %>
<%= f.text_field :contact_email, :class=>“fieldbox wide” %>
<!--tlf del Usuario-->
<p>
<label for="profile_tlf"><%=
I18n.t(‘tog_social.profiles.model.tlf’) %>
<%= f.text_field :tlf, :class=>“fieldbox wide” %>
<!--Web del usuario-->
<p>
<label for="profile_website"><%=
I18n.t(‘tog_social.profiles.model.website’) %>
<%= f.text_field :website, :class=>“fieldbox wide” %>
<!--CV del usuario-->
<p>
<label for="profile_pdf"><%=
I18n.t(‘tog_social.profiles.model.curriculum’) %>
<%= file_field “profile”, “pdf_file_name” %>
<%=
I18n.t(‘tog_social.profiles.model.curriculum_help’) %>
<!--Imagen del usuario-->
<p>
<label for="profile_icon"><%=
I18n.t(‘tog_social.profiles.model.avatar’) %>
<%= icon_for_profile(@profile, ‘big’)%>
<%= file_field “profile”, “icon” %>
<%=
I18n.t(‘tog_social.profiles.model.avatar_help’) %>
<div class="actions">
<%= submit_tag
I18n.t(‘tog_social.profiles.member.update_profile’), {:accesskey =>
“s”, :class=>“button mainaction”} %>
<% end -%>
<!--Mostramos la posibilidad de aadir responsables de la empresa-->
<hr class="wide" />
<% end -%>
<% form_for :responsible, :url =>
member_profile_path(@profile), :html => {:method
=> :put, :multipart=>true} do |f| -%>
<script type="text/javascript">
function new_responsible(i, n) {
$('fs_responsible_' + n).toggle();
$('link_fs_photo_' + i).toggle();
$('link_fs_photo_' + n).toggle();
}
</script>
<% 5.times do |i| -%>
<div class="fields">
<fieldset id="fs_responsible_<%=i%>" <%if
i>0%>style=“display:none”<%end%>>
<
%= I18n.t(“tog_social.profiles.model.responsible_name”) %> <%=
text_field “responsible[#{i}]”, {:class => “fieldbox”, :size =>
“40”} %>
<
%= I18n.t(“tog_social.profiles.model.responsible_email”) %> <
%= text_field “responsible[#{i}]”, {:class => “fieldbox”, :size =>
“40”} %>
<
%= I18n.t(“tog_social.profiles.model.responsible_tlf”) %> <%=
text_field “responsible[#{i}]”, {:class => “fieldbox”, :size =>
“40”} %>
<%if i < 4 %>
<div id=“link_fs_responsible_<%=i%>” <%if
i>0%>style=“display:none”<%end%>>
<%=
I18n.t(“tog_social.profiles.member.add_one_more_responsible”) %>
<%end%>
<% end -%>
</div>
</fieldset>
<br />
<div class="actions">
<%= submit_tag
I18n.t(‘tog_social.profiles.member.update_responsibles’), {:accesskey
=> “s”, :class=>“button mainaction”} %>
<% end -%>
and i want to know how can i add the second form about responsibles?
thanks