I am using simple_form in rails to create certain events. To create a new event, you are required to login as a user. The form will ask the user to enter the event name, start date, and end date. When the user clicks the submit button, I want the form to automatically update the attribute user_id in the database.
Right now in the database, the user_id field in the events table is always set to null. However I need this attribute to be set to:
events.user_id = current_user.id
Here is my events table for more info: 
Note: I manually entered the values for user_id in this database.
Question: How do I update a database attribute, after a user clicks submit? Or is there a default way of always setting the user_id when a new event is created?
Here is the code in the new.html.erb events view
<%= simple_form_for(@event) do |f| %>
<%= f.error_notification %>
<div class="form-inputs">
<%= f.input :name %>
<%= f.input :start_at %>
<%= f.input :end_at %>
</div>
<div class="form-actions">
<%= f.button :submit %>
</div>
<% end %>
In your create method in your event controller, add your
before the save.
e.g. if you create the event (in the
def createmethod) with@event = Event.new(params[:event])then do
@link.user_id = current_user.id on the next lineYou can probably do
@link.user = current_userand rails will figure the id out.