Reputation: 1090
I have two databases in my app. One is Projects, that holds data on projects created in the app and another is User that I made when installing the Devise gem that holds the usernames and passwords of all the people that can use the app.
I have a page where the user can create a new project to be submitted into the database.
I am trying to get the :username
field data of the current user from the User database to be submitted along with the data they enter to a new field called username_project
.
<%= stylesheet_link_tag "form" %>
<%= form_for(@project) do |f| %>
<%= f.select( :username_project, User.all.map {|p| [p.:username]}) %>
<%= f.submit "Create New Project", :class => "button" %>
<% end %>
At the moment, there is a drop down that shows the Usernames stored in the database, but I am trying to get the <%= current_user.username %>
value to be submitted as the username_project value, when the user hits submit. I am new to rails so go easy on me. Thanks in advance.
Update:
<%= stylesheet_link_tag "form" %>
<%= form_for(@project) do |f| %>
<%= current_user.username %>
<%= f.hidden_field :username_project, :value => current_user.username %>
<%= f.submit "Create New Project", :class => "button" %>
<% end %>
Upvotes: 0
Views: 146
Reputation: 5933
Use hidden_field helper:
<%= stylesheet_link_tag "form" %>
<%= form_for(@project) do |f| %>
<%= f.hidden_field :username_project, :value => current_user.username %>
<%= f.submit "Create New Project", :class => "button" %>
<% end %>
Upvotes: 1