Hi Everyone,
Hope You all are good and doing well. Guys I am here to discuss one of my problem that I am facing while using two diferent models to store values in one table.
Here I am describing you my problem Hope anyone can help me out.
I have one model 'faculty.rb', and a controller 'faculties_controller.rb', Using this controller the values are stored in 'facuties' table.
Means, 'faculties_controller' ---> (Including Fields Validation of form) accessing ---> 'faculty.rb' (MODEL) ---> (After Saving, Values are going into) ---> 'faculties' TABLE
Now I am creating another controller, i.e 'faculty_admin_controller.rb' (with ruby script/generate controller faculty_admin new create edit update), I have not created its model (i.e without generating script/generate model command, I am creating a Model Manually), Say 'faculty_admin.rb' (in app/models).
The Problem arises here, that, I want both these two models should access same table i.e 'faculties' TABLE. Actually this whole thing is a Signup Process but for two different Users. For the First User Some Values are going to be stored in 'faculties' TABLE, while for the second user the values will also store in the same table, but those two users have different models and different controller.
Now what I have done till now,
app/controller/faculties_controller.rb
def new
@faculties = Faculty.new
end
def create
@faculties = Faculty.new(params[:faculty])
@faculties.save
"some action"
end
in app/model/faculty.rb
class Faculty < ActiveRecord::Base
**** Fields Validations *****
end
in app/views/faculties/new.rhtml
<% form_tag %>
****** Number of Fields That we want to store*******
<% end %>
Now on the second hand,
app/controller/faculty_admin_controller.rb
def new
@faculties = Faculty.new
end
def create
@faculties = Faculty.new(params[:faculty])
@faculties.save
end
in app/models/faculty_admin.rb (which I have created Manually)
class FacultyAdmin < ActiveRecord::Observer
def after_create(faculty_admin)
FacultyNotifier.validates_adminfaculty(@faculty)
end
end
in app/models/faculty_notifier.rb
class FacultyNotifier < ActiveRecord::Base
def adminfaculty
validates_presence_of :email
attr_protected :hashed_password, :enabled
attr_accessor :password
end
end
Now, Please Anyone can tell me where I am wrong?? Please Reply. I will be very thankful to You.
--
___________________
Puneet Pandey
Senior Software Engineer
Safew Technology Labs
pun...@safewlabs.comhttp://www.safewlabs.comhttp://puneetitengineer.wordpress.com