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

  • Home
  • SEARCH
  • 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 8850085
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:49:04+00:00 2026-06-14T12:49:04+00:00

I’ve created a simple Rails application where users can register to attend events .

  • 0

I’ve created a simple Rails application where users can register to attend events. To create a pleasing user experience, an unidentified user can browse the events and then if they see one they’d like to event they can click ‘register for the event’. Using Twitter Bootstrap, the application then presents the user with a modal (popup) asking them to register first, to attend the event.

The form on the modal is as follows:

simple_form_for @user do |f|
  f.input :name, :placeholder => "Name", :label => false
  f.input :email, :placeholder => "Email", :label => false
  f.input :postcode, :placeholder => "Postcode", :label => false
  hidden_field_tag :event_id, @event.id
  f.button :submit, "Sign me up for this event"
end

So, you can see that basically I pass in an event_id value to the user controller’s create action. To handle this the create action becomes:

  def create
    if params[:event_id].blank?
      event_registration = false
    else
      event_id = params[:event_id].to_s
      event_registration = true
    end

    if event_registration == true
      # The user is being created as part of signing up to an event
      @user_check = User.find_by_email(params[:user][:email])

      unless @user_check.nil?
        # The user already exists, but the visitor forgot
        @user = @user_check
      else
        # The user is a new sign up
        @user = User.new(params[:user])
      end

      # Now create the attendance for the user
      @event = Event.find(event_id)
      @attendance = @event.attendances.new
      @attendance.attendee = @user
      @attendance.save

      redirect_target = event_attendance_thank_path(@event, @attendance)

    else
      # The user is being created cleanly

      @user = User.new(params[:user])
    end

    if @user.save
      redirect_to root_path, notice: "Thanks for signing up, check your email"
    else
      # We should destroy the failing attendance?
      redirect_to root_path, alert: "Something's up with the signup.  Have you already registered with this email address?"
    end
  end

To me, handling this level of complexity in the controller feels messy, and I’m wondering what better ways I might go about this?

Any help or pointers to refactor this would be greatly appreciated.

  • 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-14T12:49:05+00:00Added an answer on June 14, 2026 at 12:49 pm

    If it is possible for users that are already signed and logged in to mark their attendance for events, you should use the same piece of code in both places. Just create helper that will mark users’ attendance and call it from both UsersController#create and Events#attend (or whatever it is called) actions.

    Now — if you have heard of “fat model, skinny controller” pattern, you are probably starting to notice it is a place you could use it.

    Just create User model method to attend some event, that will accept id, or event itself as an argument. This way you could simply write in your controller:

    User.create(...).tap do |user|
      user.attend(params[:event_id]) if params[:event_id]
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string

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.