成功登录ruby on rails后的用户特定重定向

成功登录ruby on rails后的用户特定重定向,ruby,ruby-on-rails-3,Ruby,Ruby On Rails 3,目前我正在开发一个短信应用程序。我使用设计gem进行身份验证,使用载波进行上传。我的问题是,成功登录后,用户必须重定向到自己的页面,不同的用户将重定向到不同的页面 用户模型 class User < ActiveRecord::Base # Include default devise modules. Others available are: # :token_authenticatable, :encryptable, :confirmable, :lockable, :ti

目前我正在开发一个短信应用程序。我使用
设计gem
进行身份验证,使用
载波进行上传。我的问题是,成功登录后,用户必须重定向到自己的页面,不同的用户将重定向到不同的页面

用户模型

class User < ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and    :omniauthable
   devise :database_authenticatable, :registerable,:recoverable, :rememberable, :trackable, :validatable
   # Setup accessible (or protected) attributes for your model
   attr_accessible :email, :password, :password_confirmation, :remember_me
   # attr_accessible :title, :body
   has_many :sms
 end
class Sm < ActiveRecord::Base
  attr_accessible :Messages, :Mobile_no, :Nickname, :Templates
  validates_presence_of :Mobile_no
  validates_length_of :Mobile_no, :minimum => 10, :maximum => 10, :allow_blank => true
  validates :Mobile_no, :numericality => {:only_integer => true}
  attr_accessible :sm_id, :name, :image
  belongs_to :sm
  mount_uploader :image, ImageUploader
  validate :image_size_validation, :if => "image?"  

  def image_size_validation
    errors[:image] << "should be less than 1MB" if image.size > 1.megabytes
  end

  validates :image, allow_blank: true, format: {
    with: %r{\.(xls|xlsx|csv|txt)\z}i,
    message: 'must be a TXT, CSV, XLS, or XLSX'
  }, if: :filename_has_extension?

  def filename_has_extension?
    !(image.to_s =~ /\.[a-z]{1,4}\z/).nil?
  end
  belongs_to :user
end
class用户
Sm型号

class User < ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and    :omniauthable
   devise :database_authenticatable, :registerable,:recoverable, :rememberable, :trackable, :validatable
   # Setup accessible (or protected) attributes for your model
   attr_accessible :email, :password, :password_confirmation, :remember_me
   # attr_accessible :title, :body
   has_many :sms
 end
class Sm < ActiveRecord::Base
  attr_accessible :Messages, :Mobile_no, :Nickname, :Templates
  validates_presence_of :Mobile_no
  validates_length_of :Mobile_no, :minimum => 10, :maximum => 10, :allow_blank => true
  validates :Mobile_no, :numericality => {:only_integer => true}
  attr_accessible :sm_id, :name, :image
  belongs_to :sm
  mount_uploader :image, ImageUploader
  validate :image_size_validation, :if => "image?"  

  def image_size_validation
    errors[:image] << "should be less than 1MB" if image.size > 1.megabytes
  end

  validates :image, allow_blank: true, format: {
    with: %r{\.(xls|xlsx|csv|txt)\z}i,
    message: 'must be a TXT, CSV, XLS, or XLSX'
  }, if: :filename_has_extension?

  def filename_has_extension?
    !(image.to_s =~ /\.[a-z]{1,4}\z/).nil?
  end
  belongs_to :user
end
class Sm10,:maximum=>10,:allow\u blank=>true
验证:Mobile\u no,:numericality=>{:only\u integer=>true}
属性可访问:sm\u id,:name,:image
属于:sm
挂载上传器:图像,图像上传器
验证:图像大小验证,如果=>“图像?”
def图像大小验证
错误[:图像]1.MB
终止
验证:图像,允许空白:真,格式:{
使用:%r{\(xls | xlsx | csv | txt)\z}i,
消息:“必须是TXT、CSV、XLS或XLSX”
},如果::filename\u具有扩展名?
def filename_是否有扩展名?
!(image.to_s=~/\[a-z]{1,4}\z/).nil?
终止
属于:用户
终止

您应该为ApplicationController中的方法在\u路径\u中的\u签名\u后进行定义

  def after_sign_in_path_for(resource)
    # resource is commonly a User class object
    if resource.admin?
      # redirect somewhere
    else
      # redirect somewhere else
    end
  end

谢谢安德烈的回复。。我已尝试使用该代码,但我的问题没有解决:(我有两种模式1.用户2.短信..对于用户模式,我使用Desive gem创建授权登录页面。当用户登录后,我将重定向到sms/新页面,在那里我将键入要发送的消息..这里我的目标是当用户123@yahoo.com登录后,他必须查看他自己发送的消息,但当用户123@yahoo.com登录后,他可以查看包括其他用户消息在内的所有消息…您是否在模型之间建立了关联?因此,在用户登录后,您可以通过调用current_user.sms来获取所有用户的短信。我无法满足我的期望…:(请您进一步解释。)