이것은 레일 협약과는 다소 다르지만 사용자 세션 인증과 사용자 등록을 모두 관리하는 컨트롤러가 하나 있습니다. 이 문제를 해결하는 방법을 알아내는 데 어려움을 겪고 있습니다.로그인 및 등록 페이지를 통합하셨습니까?
지금까지 사용자 컨트롤러와 세션 컨트롤러를 병합하고 '새로운'방법으로 새로운 사용자 세션과 새 사용자 인스턴스를 제공했습니다.
레일 3에 새로운 경로가 있지만이 항목에 대한 양식을 생성하는 방법을 파악하는 데 어려움을 겪고 있습니다. 다음은
코드입니다 :user_controller.rb
class UserController < ApplicationController
def new
@user_session = UserSession.new
@user = User.new
end
def create_user
@user = User.new(params[:user])
if @user.save
flash[:notice] = "Account Successfully Registered"
redirect_back_or_default signup_path
else
render :action => new
end
end
def create_session
@user_session = UserSession.new(params[:user_session])
if @user_session.save
flash[:notice] = "Login successful!"
redirect_back_or_default login_path
else
render :action => new
end
end
end
전망
<div id="login_section">
<% form_for @user_session do |f| -%>
<%= f.label :email_address, "Email Address" %>
<%= f.text_field :email %>
<%= f.label :password, "Password" %>
<%= f.text_field :password %>
<%= f.submit "Login", :disable_with => 'Logining...' %>
<% end -%>
</div>
<div id="registration_section">
<% form_for @user do |f| -%>
<%= f.label :email_address, "Email Address" %>
<%= f.text_field :email %>
<%= f.label :password, "Password" %>
<%= f.text_field :password %>
<%= f.label :password_confirmation, "Password Confirmation" %>
<%= f.text_field :password_confirmation %>
<%= f.submit "Register", :disable_with => 'Logining...' %>
<% end -%>
</div>
은 내가 사용할 필요가 상상/사용자/new.html.erb : 홈페이지 => 그 양식에 대한 것이지만, 어떻게 지정해야할지 확신이 서지 않습니다.
routes.rb 내에서 아직 Users 또는 UserSessions 중 하나를 자원으로 지정해야합니다 (이것이 가장 좋은 방법이라고 확신하지는 못했지만 ...).
는 내가 좋아하는 것그러나, 등록 및 같은 페이지에 로그인 하고 다음을 수행하여이를 구현 :
routes.rb이를 해결 갈 수있는 가장 좋은 방법은 무엇
match 'signup' => 'user#new'
match 'login' => 'user#new'
을 ? 이 같은 것을 수행하여 URL을 specificy 수 있습니다 양식에