0
我試圖通過註冊從別人獲得的電子郵件地址和密碼(以下HTML)如何在Ruby on Rails中將數據從輸入字段傳遞到數據庫(解析)?
<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
我UserController中:
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
這並不奏效,但我確定這是我編寫代碼的方式。該教程幫助。謝謝! – Leigha 2012-08-17 18:56:17