im a noob with rails and I cant understand why a hidden field that i have in a form is not updating in the table. My form looks like this:
<%= form_for(@cricket_club_advert) do |f| %>
<% current_user_id = current_user.id %>
<%= hidden_field_tag "user_id", current_user_id %>
<% if @cricket_club_advert.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@cricket_club_advert.errors.count, "error") %> prohibited this cricket_club_advert from being saved:</h2>
<ul>
<% @cricket_club_advert.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="row">
<div class="large-6 columns">
<%= f.label "Title" %>
<%= f.text_field :title %>
</div>
</div>
<div class="row">
<div class="large-6 columns">
<%= f.label "Type of Player Required" %>
<%= f.text_field :player_type %>
</div>
</div>
I have added the field user_id to the accepted params, this can be seen here:
def cricket_club_advert_params
params[:cricket_club_advert].permit(:user_id, :title, :player_type, :description, :airfares, :accomadation, :job, :incentives)
end
However, when ever i create or edit a new record the field does not get updated and no errors are created.
If I make the field in the form a text_field with the id user_id it works fine.
Thanks in advance
Aucun commentaire:
Enregistrer un commentaire