设计:将页面注册为欢迎/登陆页面,然后到用户个人资料 [英] Devise: Sign Up Page as Welcome/Landing Page then to User Profile

查看:18
本文介绍了设计:将页面注册为欢迎/登陆页面,然后到用户个人资料的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用设计,我如何使我的注册成为我的登陆/欢迎页面,然后在注册后他们进入网站内部的个人资料/登录区域?

我想弄清楚如何让 Facebook 成为网站两侧的位置;用户只有在注册或登录后才能查看外部(注册、关于、联系等)和内部(个人资料、退出等).

谢谢.

附言我是 Ruby on Rails 的新手并正在创建应用程序,但我确实使用 Rails 3 教程进行了身份验证系统,我了解开始使用 Devise 的大多数事情,我只是不知道从哪里开始这种情况.

我打算使用 2 种应用程序布局,一种是注册前的 layouts/welcome.html.erb 和 PagesController(关于、条款等),另一种是用于登录用户的 layouts/application.html.erb 与 ApplicationController(配置文件、新闻、添加等),这是最好的步骤吗?

解决方案

这是我使用 Rails 3.1.0 和 Devise 1.5.0 的新方法和更新方法:

routes.rb

root :to =>页面#redirect_to_sign_up"devise_for : 用户做得到欢迎"=>"设计/注册#new", :as =>:new_user_registration获取帐户设置"=>设计/注册#edit"获取登录"=>设计/会议#new"得到sign_out"=>设计/会话#destroy"获取新密码",:to =>设计/密码#new"结尾匹配家",:to =>user_pages#home"命名空间:用户做根:到 =>user_pages#home"结尾

application_controller.rb

class ApplicationController <动作控制器::基础保护免受伪造受保护def after_sign_in_path_for(资源)storage_location_for(:user) ||根路径结尾私人的def after_sign_out_path_for(资源)storage_location_for(:user) ||根路径结尾结尾

pages_controller.rb

class PagesController <应用控制器def redirect_to_sign_up如果已登录?.空白?redirect_to new_user_registration_path别的重定向到 home_path结尾结尾结尾

user_pages_controller.rb

class UserPagesController <应用控制器before_filter :authenticate_user!定义家结尾定义配置文件结尾结尾

Using devise, how do i make my Sign Up as my landing/welcome page and then after sign up they go inside the site to the Profile/signed in area?

I am trying to figure out how to make it like where Facebook their is two sides of the website; the Outside (sign up, about,contact,etc) and The Inside (Profile,sign out,etc) for Users only after sign up or sign in.

Thank you.

P.S. I am new at Ruby on Rails and creating applications but i did do the authentication system with the Rails 3 Tutorial, i understand most things to start using Devise, i jst dont know where to start with this situation.

I was going to use 2 application layouts, 1 before sign up which is layouts/welcome.html.erb with PagesController (about,terms,etc) and the other for signed in users which will be layouts/application.html.erb with ApplicationController (profile,news,add,etc), is this the best steps?

解决方案

This my new and updated way using Rails 3.1.0 and Devise 1.5.0:

routes.rb

root :to => "pages#redirect_to_sign_up"

devise_for :users do
  get "welcome" => "devise/registrations#new", :as => :new_user_registration
  get "account_settings" => "devise/registrations#edit"
  get "sign_in" => "devise/sessions#new"
  get "sign_out" => "devise/sessions#destroy"
  get "new_password", :to => "devise/passwords#new"
end

match 'home',      :to => "user_pages#home"

namespace :user do
  root :to => "user_pages#home"
end

application_controller.rb

class ApplicationController < ActionController::Base
  protect_from_forgery

  protected

  def after_sign_in_path_for(resource)
    stored_location_for(:user) || root_path
  end

  private

  def after_sign_out_path_for(resource)
    stored_location_for(:user) || root_path
  end
end

pages_controller.rb

class PagesController < ApplicationController
  def redirect_to_sign_up
    if signed_in?.blank?
      redirect_to new_user_registration_path
    else
      redirect_to home_path
    end
  end
end

user_pages_controller.rb

class UserPagesController < ApplicationController
  before_filter :authenticate_user!

  def home
  end

  def profile
  end
end

这篇关于设计:将页面注册为欢迎/登陆页面,然后到用户个人资料的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆