Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8851171
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:05:17+00:00 2026-06-14T13:05:17+00:00

I am using simple_form in rails to create certain events. To create a new

  • 0

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: enter image description here

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 %>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T13:05:20+00:00Added an answer on June 14, 2026 at 1:05 pm

    In your create method in your event controller, add your

    events.user_id = current_user.id
    

    before the save.

    e.g. if you create the event (in the def create method) with @event = Event.new(params[:event])
    then do @link.user_id = current_user.id on the next line
    You can probably do @link.user = current_user and rails will figure the id out.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using heroku to host a very simple signup form I create in Rails
I'm creating a basic sign up form using ruby on rails (I'm relatively new
I'm using Simple_form with Rails 3.2.1 All fine, except that I need to set
Im using the Simple form gem to setup a form on my rails app.
I'm using Rails 3.2, Carrierwave and simple_form. Currently, everything is working fine with one
I have started using jQuery and rails. I have made a simple form that
Using Ruby 1.8.7-p358, Rails 3.0.12, gem responder, gem simple-form; jquery_ujs.js I have a form
I'm using the Simpleform gem for my rails app and I have a form
I'm using simple_form for a form and passing in some URL parameters to prepopulate
I am attempting to create an API with Rails using BDD with RSpec. Rails

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.