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 8956233
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:44:39+00:00 2026-06-15T14:44:39+00:00

I have a form that, when the user submits, and the user is not

  • 0

I have a form that, when the user submits, and the user is not signed in, they receive a modal prompt to login. Once the user logs in, the modal disappears, but they have to click the submit button on the form again. It would be nice if, after successfully signing in, the modal disappeared and the form submits automatically.

So inside sessions/create.js.erb I added the following.

# create.js.erb
<% if signed_in? %>
    $('#ajax-modal').modal('hide').empty();
    $('#new_response).submit();
<% else %>
    $('#ajax-modal').html('<%= j render("sessions/form") %>').modal();
<% end %>

This works, but it’s not scalable. Firs of all, I might have other forms–not just #new_response–that require a similar behaviour. So each time I add a new form I have to edit create.js.erb and add an if (form exists) submit();. There are also other times when the modal is used for signing in but no forms are involved at all.

Is there a way to attach a hook to tell sessions/create.js.erb to submit the form only when one exists, but without having any knowledge of the form id? Basically, have that passed in.

# responses/_form.html.slim
= form_for [@discussion, @response], remote: true do |f|
    = f.label :content, "Comments"
    = f.text_area :content, rows: 8
    = f.submit "Reply", class: 'btn btn-success reply', 'data-disable-with' => "Reply"

# Responses controller
class ResponsesController < ApplicationController
  before_filter :require_authentication, except: :index
  ...

  def require_authentication
    redirect_to signin_path unless signed_in?
  end
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-15T14:44:40+00:00Added an answer on June 15, 2026 at 2:44 pm

    You can use some sort of way to track which form triggered the submit, e.g.

    # ResponsesController
    class ResponsesController < ApplicationController
      before_filter :require_authentication, except: :index
    
      def require_authentication
        session[:form_track_code] = params[:form_track_code] if [:put, :post].include?(request.method_symbol) && params[:form_track_code].present?
    
        redirect_to signin_path unless signed_in?
      end
    end
    
    # SessionsController
    class SessionsController < ApplicationController # or devise?
      def create
        @form_track_code = session.delete[:form_track_code]
        super # or whatever you implemented
      end
    end
    
    # create.js.erb
    <% if signed_in? %>
        $('#ajax-modal').modal('hide').empty();
        <% if @form_track_code.present? %>
          $('input[type=hidden][value="<%= @form_track_code %>"]').parents('form').submit();
        <% end %>
    <% else %>
        $('#ajax-modal').html('<%= j render("sessions/form") %>').modal();
    <% end %>
    
    # application.js
    $('form[data-remote=true]').each(function() { $(this).append('<input type="hidden" name="form_track_code" value="' + Math.random() + '" />'); });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form that the user submits and returns a result, but it
I have the code below on form so that the user submits the form
I currently have form that checks if a user has unsubmitted changes when they
I have a form that a user submits. The form is for a user.
I'd like to have a modal window that gets displayed when the user submits
I have a registration form that user submits, data is sent using isset($_POST) to
I have a form that requires the user to enter some information. If they
So I have a form that the user fills out, when submitted an new
So I have a form that accepts some input from a user that may
Here's what I want to do. I have a form that the user fills

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.