Rails アプリケーションで認証にデバイスを使用しています。現在、私は2つのモデルを持っています:
Users
Accounts
アカウントはユーザーに属し、ユーザーは 1 つのアカウントを持ちます。
私のアカウント モデルには、名前とサブドメインが含まれています。私のユーザー モデルには電子メールとパスワードがあります
account.rb には次のものがあります。
class Account < ActiveRecord::Base
attr_accessible :name, :subdomain
belongs_to :user
end
そしてuser.rbで:
class User < ActiveRecord::Base
devise :database_authenticatable, :registerable, :Trackable
attr_accessible :email, :password, :password_confirmation, :account_attributes, :account
has_one :account
end
ユーザーがサインインした後、アカウントから名前と sudbomain などを取得する必要があります。
私のapplication_controller.rbには次のものがあります:
def after_sign_in_path_for(resource)
if resource.is_a?(User)
user_path
else
super
end
end
def current_account
@iduser = session[:user_id]
@current_account ||= Account.find(@iduser) if @iduser
end
helper_method :current_account
そしてlayout.html.erbで
<% if current_account %>
<%= current_account.name %> <%= current_account.subdomain %>
<% end %>
<% if user_signed_in? %>
|
<%= link_to destroy_user_session_path, :class => "btn btn-mini btn-danger", :method => :delete do %>
<i class="icon-off icon-white"></i> logout
<% end %>
<% end %>
ただし、名前とサブドメインは表示されません。それらを表示するにはどうすればよいですか?