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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T11:55:14+00:00 2026-06-02T11:55:14+00:00

I’ trying to create a simple login form where users should be able to

  • 0

I’ trying to create a simple login form where users should be able to sign in. I want it to redirect to the users show action, but instead it redirects to .../sessions, I want it to redirect to `…/users/1. I have a session controller that looks like this (I have been following Rails Tutorial Book)

def create
    user = User.find_by_email(params[:email])
    if user && user.authenticate(params[:password])
      sign_in user
      redirect_to user
    else 
      render 'new'
    end
  end 

I have tried to change redirect_to userto redirect_to users_path(user) but it doesn’t work.

My routes looks like this:

  root :to => 'pages#home'

  resources :users
  resources :sessions, only: [:new, :create, :destroy]

  match '/signup',  to: 'users#new'
  match '/signin',  to: 'sessions#new'
  match '/signout', to: 'sessions#destroy', via: :delete

And sessions/sessions.new.html.erb looks like this:

<%= form_tag sessions_path do %>
  <%= text_field_tag :email, params[:email], :placeholder => "E-post" %>
  <%= password_field_tag :password, nil, :placeholder => "Lösenord" %>
  <%= submit_tag "Logga in" %>
<% end %>

My rails skills is a bit rusty, so it’s probably something basic.

Update

I managed to “solve” it by creating a index action in my session controller which redirect to the correct path when getting called. I don’t’ know (or think) this is the most optimal way to do it. The original problem was that when a user signed in, it for some reason got redirected to /sessions, and not the root path which I want. When or if the user updated the browser the application crashes (since I didn’t have a index action in my session controller). I don’t know why it isn’t redirecting to the right path, I did also try redirect_to user_path(user), but with the same result. Any tips on how to solve it the “right” way, would be great! I also had the same problem when users signed up, it redirected to /users instead of /.

  • 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-02T11:55:28+00:00Added an answer on June 2, 2026 at 11:55 am

    It sounds like your action is falling to the else condition and consequently doing the render :action=>”new” and not the redirect you’re looking for. In the case of the render action, the url would show something like you’ve described “…/sessions” since the form is likely (and correctly) doing a POST to that url but has failed and is re-rendering without redirecting.

    In other words, I think your user.authenticate(…) is probably failing or for some reason returning nil or false.

    UPDATE:

    Since you’re using jquerymobile, the page that you redirect to is being AJAXed in. The documentation (see the Redirects and linking to directories section) says that you can use a data-url attribute on the div that has the data-role as page to control the url. So, for your example, wrap the content in app/pages/home in a ‘page roled’ div tag with the data-url set for whatever you want…for example:

    <div data-role="page" data-url="/home">
    <% if signed_in? %>
      <%= render "signed_in"%>
    <% else %>
      <%= render "home_page" %>
    <% end %>
    </div>
    
    • 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
I want to count how many characters a certain string has in PHP, but
I have a French site that I want to parse, but am running into
Seemingly simple, but I cannot find anything relevant on the web. What is the
I want to construct a data frame in an Rcpp function, but when I
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
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 string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

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.