I am relatively new to rails – therefore the question should be very easy to answer. I tried to find a solution for the problem in other posts, but I could find it (probably because I don’t know the right vocabulary right now).
Here is my question/ case:
I have two models:
1) Model one: Users
2) Model two: FreelancerData
They are connect through “User has one FreelancerData” and “FreelancerData belongs_to User”. The FreelancerData contains three field “daily_rate”, “status” and “user_id” (= foreign field).
Now I want to create a Form with form_for, in which I can fill in the FreelancerData for the current user.
I tried the following code, but this does not work
<% provide(:title, "Edit freelancer") %>
<div class="row">
<aside class="span4">
<section>
<%= render ('layouts/profile') %>
</section>
</aside>
<div class="span8">
<h1>Edit your profile</h1>
<h5>Please edit your current working status and your daily rate:</h5>
<%= form_for @user.freelancer_data do |f| %>
<%= render 'shared/error_messages', object: f.object %>
<%= f.label :status %>
<%= f.select :status, ['Busy', 'Available'] %>
<%= f.label :daily_rate, "Daily rate in Euro ('.' and ',' are not allowed)" %>
<%= f.text_field :daily_rate %>
<%= f.submit "Save changes", class: 'btn-large btn-primary' %>
<% end -%>
<h5>If you want to change your picture, you can do it here:</h5>
<%= gravatar_for @user %>
<a href="http://gravatar.com/emails">change</a>
</div>
</div>
So my question is: Is it possible to edit data of a associated table FreelancerData through the User Data?
Yup. You can use fields_for. Check out this link.