Note that there are some explanatory texts on larger screens.

plurals
  1. PORuby on the rails, devise and using user to limit existing model
    text
    copied!<p>I am very new to Ruby (2-3 days) and am using it on an existing DB. I have a user table (previously built in Joomla) and have managed to get it working (well, logging in and out), but i need to constrain another model i.e. 'Leads' to the user that is logged in. </p> <p>I have been able to get ALL the current 'leads' output and using CRUD operations, but i would like to know how to limit the data based on the user that is logged in.</p> <p>The 'leads' model was generated using scaffolding and the 'set_table_name' and 'set_primary_key' attributes have been overridden. I have also added</p> <p><code>belongs_to :user, :class_name =&gt; "user", :foreign_key =&gt; "leadid"</code> </p> <p>to the model.</p> <p>The 'user' model is as follows </p> <pre><code>class User &lt; ActiveRecord::Base # Include default devise modules. Others available are: # :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable `establish_connection :web_development set_table_name "users" set_primary_key "id" has_many :leads, :class_name =&gt; "Lead", :foreign_key =&gt; "LeadID" devise :database_authenticatable, :registerable, :recoverable, :rememberable, :validatable # Setup accessible (or protected) attributes for your model attr_accessible :email, :password, :password_confirmation, :remember_me alias :devise_valid_password? :valid_password? def valid_password?(password) return true (temp to bypass the password) end end </code></pre> <p>Many thanks Rudy</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload