Ruby on rails 使用Rails创建登录页
我正在尝试为我正在创建的应用程序创建登录页。有没有关于我该怎么做的建议。没有什么复杂的,只要一个页面上有一个表单,用户可以添加他们的电子邮件地址并将其放入数据库。我不确定我是否应该用Desive Gem来做这个?我觉得有一个更简单的方法。非常感谢。我是个超级傻瓜。刚刚完成的onemonthrails。Desive是一个身份验证库。如果您希望用户注册以访问应用程序的不同部分(需要身份验证),那么您可以使用Desive 如果你只想从访问你的应用程序的人那里收集数据,你可以创建一个简单的资源Ruby on rails 使用Rails创建登录页,ruby-on-rails,devise,splash-screen,Ruby On Rails,Devise,Splash Screen,我正在尝试为我正在创建的应用程序创建登录页。有没有关于我该怎么做的建议。没有什么复杂的,只要一个页面上有一个表单,用户可以添加他们的电子邮件地址并将其放入数据库。我不确定我是否应该用Desive Gem来做这个?我觉得有一个更简单的方法。非常感谢。我是个超级傻瓜。刚刚完成的onemonthrails。Desive是一个身份验证库。如果您希望用户注册以访问应用程序的不同部分(需要身份验证),那么您可以使用Desive 如果你只想从访问你的应用程序的人那里收集数据,你可以创建一个简单的资源 # ge
# generate model
bundle exec rails g model UserSignup email
# run migration
bundle exec rake db:migrate
然后配置您的路由
# config/routes.rb
resources :user_signups, only: [:new, :create]
root 'user_signups#new'
然后您的控制器:
# app/controllers/user_signups_controller.rb
class UserSignupsController < ApplicationController
def new
@user_signup = UserSignup.new
end
def create
@user_signup = UserSignup.new(user_signup_params)
if @user_signup.save
redirect_to root_url, notice: "Thank you for expressing interest."
else
render action: 'new', alert: "Signup failed."
end
end
private
def user_signup_params
params.require(:user_signup).permit(:email)
end
end
#app/controllers/user_-signups_-controller.rb
类UserSignupsController
最后,你的观点是:
# app/views/user_signups/new.html.erb
<h1>Signup to Express Your Interest!</h1>
<%= form_for @user_signup do |f| %>
<% if @user_signup.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@user_signup.errors.count, "error") %> prohibited your registration from being completed:</h2>
<ul>
<% @user_signup.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :email %><br>
<%= f.text_field :email %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
#app/views/user_signups/new.html.erb
注册以表达您的兴趣!
禁止您完成注册:
这应该让您开始,您可以开始充实页面、电子邮件验证等。此外,您可能希望从创建操作重定向到root\u url
以外的其他位置,但您可能知道如何做到这一点
这样就可以在数据库中获取数据,但如果您想通过应用程序(而不是直接在数据库中)查看收集的数据,则可以使用类似Desive的工具锁定应用程序中显示用户数据的位置。Desive是一个身份验证库。如果您希望用户注册以访问应用程序的不同部分(需要身份验证),那么您可以使用Desive
如果你只想从访问你的应用程序的人那里收集数据,你可以创建一个简单的资源
# generate model
bundle exec rails g model UserSignup email
# run migration
bundle exec rake db:migrate
然后配置您的路由
# config/routes.rb
resources :user_signups, only: [:new, :create]
root 'user_signups#new'
然后您的控制器:
# app/controllers/user_signups_controller.rb
class UserSignupsController < ApplicationController
def new
@user_signup = UserSignup.new
end
def create
@user_signup = UserSignup.new(user_signup_params)
if @user_signup.save
redirect_to root_url, notice: "Thank you for expressing interest."
else
render action: 'new', alert: "Signup failed."
end
end
private
def user_signup_params
params.require(:user_signup).permit(:email)
end
end
#app/controllers/user_-signups_-controller.rb
类UserSignupsController
最后,你的观点是:
# app/views/user_signups/new.html.erb
<h1>Signup to Express Your Interest!</h1>
<%= form_for @user_signup do |f| %>
<% if @user_signup.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@user_signup.errors.count, "error") %> prohibited your registration from being completed:</h2>
<ul>
<% @user_signup.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :email %><br>
<%= f.text_field :email %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
#app/views/user_signups/new.html.erb
注册以表达您的兴趣!
禁止您完成注册:
这应该让您开始,您可以开始充实页面、电子邮件验证等。此外,您可能希望从创建操作重定向到root\u url
以外的其他位置,但您可能知道如何做到这一点
这样就可以在数据库中获取数据,但如果你想通过应用程序(而不是直接在数据库中)查看收集的数据,这时你可以使用类似Desive的工具锁定应用程序中显示用户数据的位置。你应该通过RailsApp的Daniel Kehoe进行查看。这是一个很好的起点,他甚至有一个教程(虽然收费,但很便宜)
Desive更多的是用于用户身份验证,如果您只是收集电子邮件地址,则不需要它。您应该查看RailsApp的Daniel Kehoe。这是一个很好的起点,他甚至有一个教程(虽然收费,但很便宜)
Desive更多的是用于用户身份验证,如果您只是收集电子邮件地址,则不需要它。我正在寻找一个只表示欢迎的静态网站。我们是一个这样这样做的人。请在下面注册,以便在我们启动时收到电子邮件。我是个超级初学者。因此,我需要一个详细的解释如何从开始到结束感谢帮助。我正在寻找一个静态网站,只是说欢迎更多。我们是一个这样这样做的人。请在下面注册,以便在我们启动时收到电子邮件。我是个超级初学者。所以我需要一个关于如何从开始到结束的详细解释,谢谢你的帮助。
gem安装rails-v3.2.15
现在你有了rails 3.2,从github克隆项目并运行捆绑包,或者你可以使用rails 4,只需看看@Helios的answerFor rails 4.0,使用(免费)学习rails示例应用程序:随书提供。gem安装rails-v3.2.15
现在您有了rails 3.2,从github克隆项目并运行捆绑包,或者您可以使用rails 4,只需查看@Helios的AnswerforRails 4.0,使用随书提供的(免费)学习rails示例应用程序即可。