Friday, 9 August 2013

upgrade to rails 4, can no longer register users

upgrade to rails 4, can no longer register users

I upgraded to rails 4 and now I am no longer able to register users on my
app. It seems like my gallery (carrierewave) has broken down. I have
inspected the code and can't notice anything that would stop it from
working now. I get a undefined method `galleries' and it points to def
setup_gallery: self.galleries << Gallery.create and under def create: if
@user.save
Fresh eyes on my code would be great.
Users controller:
class UsersController < ApplicationController
respond_to :html, :json
def settings
@user = User.find(id_params)
end
def new
@user = User.new
end
def profile
@profile = User.profile
end
def create
@user = User.new(user_params)
if @user.save
UserMailer.registration_confirmation(@user).deliver
session[:user_id] = @user.id
redirect_to root_url, notice: "Thank you for signing up!"
else
render "new"
end
end
def show
@user = User.find(id_params)
end
def edit
@user = User.find(id_params)
end
def index
@users = User.all
end
def destroy
User.find(id_params).destroy
flash[:success] = "User deleted."
redirect_to users_url
end
def update
@user = if current_user.has_role?(:admin)
User.find(id_params)
else
current_user
end
@user.update_attributes(user_params)
respond_with @user
end
private
def user_params
params.require(:user).permit(:name)
end
def id_params
params.require(:id).permit(:name)
end
end
User model:
# models/user.rb
after_create :setup_gallery
def received_messages
Message.received_by(self)
end
def unread_messages?
unread_message_count > 0 ? true : false
end
def unread_messages
received_messages.where('read_at IS NULL')
end
def sent_messages
Message.sent_by(self)
end
# Returns the number of unread messages for this user
def unread_message_count
eval 'messages.count(:conditions => ["recipient_id = ? AND read_at IS
NULL", self.user_id])'
end
def to_s; username
end
def has_role?(role_name)
role.present? && role.to_sym == role_name.to_sym
end
def send_password_reset
generate_token(:password_reset_token)
self.password_reset_sent_at = Time.zone.now
save!
UserMailer.password_reset(self).deliver
end
def generate_token(column)
begin
self[column] = SecureRandom.urlsafe_base64
end while User.exists?(column => self[column])
end
private
def setup_gallery
self.galleries << Gallery.create
end
end

No comments:

Post a Comment