I've the following view in RoR:
<%= form_tag(url_for :controller => 'posts', :action => 'create', method: "post") do %>
<label>Zawartość</label>
<%= text_area_tag(:content) %>
<br/>
<label>Użytkownik</label>
<%= collection_select(:user, :user_id, User.all, :id, :name ) %>
<br/>
<% end %>
And the action of controller:
def create
@post = Post.new
@post.content = params["content"]
@post.user_id = params["user[user_id]"];
@post.save!
end
Unfortunately, user_id
is saved as null. What is strange, the html is generated properly:
<select name="user[user_id]" ... >...</select>
Why?