我在我的控制人员之一(在铁路3.1号申请中)中有以下守则很好地发挥作用:
def index
#@calls = Call.all
@calls = Call.where(:destination => 12345678 ).limit(25)
respond_to do |format|
format.html # index.html.erb
format.json { render :json => @calls }
end
end
我试图从这里找到最佳操作方法,基本上每个用户都有自己的目的地代码(在这种情况下,是1245678页)。
用户能否在能够传入控制器的模式中具有价值?
实例
def index
#@calls = Call.all
@calls = Call.where(:destination => <% @user.destination %> ).limit(25)
respond_to do |format|
format.html # index.html.erb
format.json { render :json => @calls }
end
end
我确信,上述法典将不奏效,但要实现同样的东西,将做些什么?
2. 更新资料,少有新资料:
我有两个模式,一个是电话,另一个是用户。
我想这样做:
@calls = Call.where(:destination => @user.destination_id).limit(25)
如果:目的地是呼吁模式的一部分,目的地是用户模式的一部分。 每个用户都有不同的目的地——id值。
<>http://europa-eu>
Outofhours::Application.routes.draw do
ActiveAdmin.routes(self)
devise_for :admin_users, ActiveAdmin::Devise.config
get "log_out" => "sessions#destroy", :as => "log_out"
get "log_in" => "sessions#new", :as => "log_in"
get "sign_up" => "users#new", :as => "sign_up"
resources :users
resources :sessions
resources :calls
root :to => dashboards#index
resources :dashboards
end
<>strong>user model
class User < ActiveRecord::Base
attr_accessible :email, :company, :destination_id, :password, :password_confirmation
attr_accessor :password
before_save :encrypt_password
validates_confirmation_of :password
validates_presence_of :password, :on => :create
validates_presence_of :email
validates_uniqueness_of :email
validates_uniqueness_of :company
validates_uniqueness_of :destination_id
def self.authenticate(email, password)
user = find_by_email(email)
if user && user.password_hash == BCrypt::Engine.hash_secret(password, user.password_salt)
user
else
nil
end
end
def encrypt_password
if password.present?
self.password_salt = BCrypt::Engine.generate_salt
self.password_hash = BCrypt::Engine.hash_secret(password, password_salt)
end
end
end
<>唱名表决>
class Call < ActiveRecord::Base
end