I am wondering if its possible to keep the relationship and build two controllers in the same time?
Let me explain I have two models and the relationship is has follow:
Users, Locations
Users has many locations
Locations belongs_to users
I am not sure if I should add virtual field, and if so how, to the users form when creating a new user and then send longitude and latitude attribute as parameters in order to do following in my controller:
UserController#new
@users= User.new
@location = User.locations.build(params[:latitude,:longitude])
...
Here are my two questions:
- Is this the right approach?
- How do I create virtual field/hidden field used only for this time only.
Thank you
Write attr_accessor :latitude, :longitude in Location model.
attr_accessor makes reader and writer methods for Model/class objects