I am confused with this. I have a company model and a message model. Company has_many messages and messages belongs_to company. I am having problems with the data being saved to the proper company with this form is saved.
<%= form_for(@msg) do |f| %>
<%= render 'errors', :object => f.object %>
<ul class="fields">
<li>
<%= select("msg", "company_id", Company.all.collect {|p| [ p.title, p.id ] }) %>
</li>
</ul>
<ul class="fields">
<li><%= f.label :content, "Send this company your message" %></li>
<li><%= f.text_area :content %></li>
</ul>
<div id="actions">
<%= f.submit "Send" %>
</div>
<% end %>
every time this form is saved the company_id is null. My code for the controller to save is
def create
@msg = current_user.messages.build(params[:msg])
if @msg.save
flash[:success] = "New message saved"
redirect_to current_user
else
render current_user
end
end
Nothing stands out to me as to why this is not saving, can someone guide me to the right direction?
Jeff