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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T14:57:47+00:00 2026-05-21T14:57:47+00:00

I am trying to force a user to login once they call this update

  • 0

I am trying to force a user to login once they call this update action in my article controller (I am trying to work with gradual engagement) but once they login, I want to still call this action instead of halting.

 def update
    @article.attributes = params[:article]
    @article.save

    #store this article as a session variable
    session[:pending_article] = @article.body

    respond_with(@article, :location => article_url(@article))
  end

Right now I am using a before_filter for the action that requires the user to login

 def require_user
    unless current_user
      store_location
      flash[:notice] = "You must be logged in to access this page"
      redirect_to login_url
      return false
    end
  end

However, I understand that before filters halt the original action once they redirect, so update never gets called. Basically, I want a user to be logged in to save an article but I want to save their work so I’m storing the article body in a session variable which I grab later. Is there a better way to require a user to login for an action but call it afterwards anyway?

  • 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-05-21T14:57:48+00:00Added an answer on May 21, 2026 at 2:57 pm

    In your require_user method you can do something like this:

    session[:article] = params[:article]
    

    Then in your login method (/sessions/create?) do this:

    # this should take you back /articles/new,
    # you may have to move your call to store_location 
    # or manually set session[:return_to]
    redirect_back_or_default 
    

    Then in ArticlesController#new

    def new
      @article = Article.new(session[:article] || {})
    end
    

    Then the saved article params from the session are still there so the form is pre-filled out.

    Be careful storing too much content in the session though. In Rails the default session store is a cookie, and cookies only hold about 4k of data. You may need to change your session store to pull this off.

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

Sidebar

Related Questions

In wordpress I am trying to force user login first before see anything. Means
I'm creating a Ruby on Rails application, and I'm trying to create/login/logout users. This
I'm trying to force a user to be redirected to the non-www website, and,
I'm trying to limit user's posts to once a day, I was thinking about
I find my self out of ideas trying to get this app to work.
I am trying to authenticate user using LDAP I am using this code: public
I am trying to force a user to select a radio option on a
I'm trying to force an inherited class to use a custom attribute. I'm creating
I am trying to force an iframe to the exact same height as the
I'm trying to force ssl on certain pages, but also on a directory. But

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.