我正在尝试传递从注册的人那里获得的电子邮件和密码(下面的 html)
<form id="frm-signup">
<h5>Email</h5>
<input id="email" type="text" name="email" />
<h5>Password</h5>
<input id="register-password" type="password" name="password" />
/*Pass data*/
<% users = User.new %>
<% users.username = @email %>
<% users.password = @password %>
<% users.save %>
</form>
并将其传递到我的数据库中,但我似乎无法弄清楚。我可能只是结合了几种不同的方法?我是 Ruby 的新手,但我仍在搞清楚。
我的用户模型:
class User < ParseUser
fields :email, :password, :firstName, :lastName
validates_presence_of :email, :password
alias :email :username
validates_length_of :password, :minimum => 8, :allow_blank => false
has_many :items, :primary_key => "objectId"
end
我的用户控制器:
class UsersController < ApplicationController
def new
@user = User.new
end
def create
user = User.authenticate(params[:username], params[:password])
@email = params[:email].nil? 1; params[:email]
@username = params[:email].nil? 1; params[:email]
@password = params[:password].nil? 1; params[:password]
if user
session[:user_id] = user.id
redirect_to root_url, :notice => "logged in !"
else
flash.now.alert = "Invalid username or password"
render "new"
end
end
def index
end
def destroy
session[:user_id] = nil
redirect_to root_url, :notice => "Logged out!"
end
end