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

The Archive Base Latest Questions

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

I am creating a app for picture uploading. There are users, albums, pics. However,

  • 0

I am creating a app for picture uploading. There are users, albums, pics. However, when I log in and create a new album, on the redirect it logs me out for some reason. Can anyone help?

Here’s my Albums controller create action

def create
  @user = User.find(params[:user_id])
  @album = @user.albums.build(params[:album])
  @album.users << @user.friends.find(params[:users][:friend_id])
  respond_to do |format|
    if @user.save
      format.html { redirect_to user_album_path(@user, @album), notice: 'Album was successfully created.' }
      format.json { render json: @album, status: :created, location: @album}
    else
      format.html { render action: "new" }
      format.json { render json: @album.errors, status: :unprocessable_entity }
    end
  end 
end

config/routes

Pholder::Application.routes.draw do
resources :users do
  resources :friends
  resources :albums do
    resources :photos
  end
end
end

(don’t think this is necessary, but here’s the form for album/new.html.erb in case you want to see)

<%= form_for ([@user, @album]), :html => { :id => "uploadform", :multipart => true } do |f| %>
<div class="formholder">
    <%= f.label :name %>
    <%= f.text_field :name %>

    <%= collection_select(:users, :friend_id, @user.friends, :id, :name_with_initial, :multiple => true ) %>

    <%= f.label :description %>
    <%= f.text_area :description %>

    <br>

    <%=f.submit %>
</div>
<% end %>

html generated form:

<form accept-charset="UTF-8" action="/users/27/albums" class="new_album" enctype="multipart/form-data" id="uploadform" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /><input name="authenticity_token" type="hidden" value="cUx2AZc5Cxa+FZxtOWwHDZ8WSnvb4l9B2BqcWhXYmgg=" /></div>
<div class="formholder">
<label for="album_name">Name</label>
<input id="album_name" name="album[name]" size="30" type="text" />

<select id="users_friend_id" name="users[friend_id]"><option value="29">Ben</option>
<option value="30">Bally</option></select>

<label for="album_description">Description</label>
<textarea cols="40" id="album_description" name="album[description]" rows="20">
 </textarea>

<br>

<input name="commit" type="submit" value="Create Album" />

terminal log

Started POST "/users/27/albums" for 127.0.0.1 at 2012-10-08 18:51:11 -0400
Processing by AlbumsController#create as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"cUx2AZc5Cxa+FZxtOWwHDZ8WSnvb4l9B2BqcWhXYmgg=", "album"=>{"name"=>"world tour", "description"=>"fadsjkafsdjk"}, "users"=>{"friend_id"=>"29"}, "commit"=>"Create Album", "user_id"=>"27"}
  User Load (0.1ms)  SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1  [["id", "27"]]
  User Load (0.2ms)  SELECT "users".* FROM "users" INNER JOIN "friendships" ON "users"."id" = "friendships"."friend_id" WHERE "friendships"."user_id" = 27 AND "users"."id" = ? AND (status = 'accepted') LIMIT 1  [["id", "29"]]
   (0.0ms)  begin transaction
   (0.7ms)  UPDATE "users" SET "remember_token" = '0lIsogcOIkUMMWFbRWerjw', "updated_at" = '2012-10-08 22:51:11.476530' WHERE "users"."id" = 27
  SQL (0.2ms)  INSERT INTO "albums" ("created_at", "description", "name", "updated_at") VALUES (?, ?, ?, ?)  [["created_at", Mon, 08 Oct 2012 22:51:11 UTC +00:00], ["description", "fadsjkafsdjk"], ["name", "world tour"], ["updated_at", Mon, 08 Oct 2012 22:51:11 UTC +00:00]]
  SQL (0.2ms)  INSERT INTO "album_users" ("album_id", "created_at", "updated_at", "user_id") VALUES (?, ?, ?, ?)  [["album_id", 113], ["created_at", Mon, 08 Oct 2012 22:51:11 UTC +00:00], ["updated_at", Mon, 08 Oct 2012 22:51:11 UTC +00:00], ["user_id", 29]]
  SQL (0.2ms)  INSERT INTO "album_users" ("album_id", "created_at", "updated_at", "user_id") VALUES (?, ?, ?, ?)  [["album_id", 113], ["created_at", Mon, 08 Oct 2012 22:51:11 UTC +00:00], ["updated_at", Mon, 08 Oct 2012 22:51:11 UTC +00:00], ["user_id", 27]]
   (6.3ms)  commit transaction
Redirected to http://localhost:3000/users/27/albums/113
  • 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-12T13:19:18+00:00Added an answer on June 12, 2026 at 1:19 pm

    Looking at your code (link is in your comment below), here is the problem. When saving the album, you are calling @user.save! This is triggering the create_remember_token in the user model, which is causing the logout.

    Here is your code calling @user.save in the album controller:

    def create
      @user = User.find(params[:user_id])
      @album = @user.albums.build(params[:album])
      @album.users << @user.friends.find(params[:users][:friend_id])
      respond_to do |format|
        if @user.save
    

    Here is the before_save in the user model:

    class User < ActiveRecord::Base
      ....
      before_save :create_remember_token
    

    You might want to eliminate the before_save and then just call create_remember_token when the user logs in.

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

Sidebar

Related Questions

I am creating an app that allows users to create and apply for jobs.
So far I have my app taking a picture creating a new folder on
I am creating an app at the moment which take a picture of a
I'm creating an app that will have a fair amount of users. Everytime someone
I am new to iPhone development. I am creating an app where I take
I'm trying to create a simple iPhone app that displays a picture with a
am new to android and I am interested in creating an app where I
Hi i'm creating an app which have shopping cart and payment done via paypal
I am creating an app using iOS 5 SDK. I managed to push views
I am creating an app where if something occurs, it switches back to the

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.