我的问题类似于rails,用户在编辑个人资料后退出? 但我没有使用设计来登录/注册,而是使用从 Michael Hartl 的 railstutorial 第 7-9 章复制的代码。它在开发中效果很好!但是,一旦我推送到 Heroku,我的应用程序会在用户将编辑(更新)保存到他们的个人资料后将其注销。编辑正确地保存到数据库中。
这是github:https ://github.com/crowdpublishtv/crowdpublishtv
这是我的 users_controller.rb:
class UsersController < ApplicationController
before_filter :signed_in_user, only: [:index, :edit, :update]
before_filter :correct_user, only: [:edit, :update]
def index
@users = User.all
respond_to do |format|
format.html # index.html.erb
format.json { render json: @users }
end
end
def show
@user = User.find(params[:id])
@books = @user.books
respond_to do |format|
format.html # show.html.erb
format.json { render json: @user }
end
end
def blog
@user = User.find(params[:id])
respond_to do |format|
format.html # blog.html.erb
format.json { render json: @user }
end
end
def profileinfo
@user = User.find(params[:id])
respond_to do |format|
format.html # profileinfo.html.erb
format.json { render json: @user }
end
end
def booklist
@user = User.find(params[:id])
@books = @user.books
respond_to do |format|
format.html # booklist.html.erb
format.json { render json: @user }
end
end
def new
@user = User.new
respond_to do |format|
format.html # new.html.erb
format.json { render json: @user }
end
end
def edit
@user = User.find(params[:id])
@books = @user.books
@book = current_user.books.build if signed_in?
@booklist = Book.where(:user_id => @user.id)
end
def create
@user = User.new(params[:user])
if @user.save
sign_in @user
redirect_to @user
else
render 'new'
end
end
def update
@user = User.find(params[:id])
@booklist = Book.where(:user_id => @user.id)
if @user.update_attributes(params[:user])
sign_in @user
redirect_to @user
else
render 'profileinfo'
end
end
def destroy
@user = User.find(params[:id])
@user.destroy
respond_to do |format|
format.html { redirect_to users_url }
format.json { head :ok }
end
end
private
def signed_in_user
unless signed_in?
store_location
redirect_to signin_url, notice: "Please sign in."
end
end
def correct_user
@user = User.find(params[:id])
redirect_to(signin_url) unless current_user?(@user)
end
end