Note that there are some explanatory texts on larger screens.

plurals
  1. POModel Association issue in Rails
    text
    copied!<p>Hopefully this will be simple. But I've hunted for a couple hours now and can't seem to get this to work. I have users who have multiple addresses, I'm trying to use Geocoder gem to display these users by a zip code search, my code is very similar to what is in the Geocoder Railscast.</p> <p>Here's my controller attempt 1 and returns "undefined method `Addresses'"</p> <pre><code>def index if params[:search].present? @profiles = Profile.Addresses.near(params[:search], 25, :order =&gt; :distance) @title = "Therapists Near " + :search else @profiles = Profile.all @title = "Everyone" end end </code></pre> <p>This is attempt number 2, this returns "uninitialized constant ProfilesController::Addresses" (I don't know if the Profile.where bit will work, but its not even getting to that part...)</p> <pre><code>class ProfilesController &lt; ApplicationController def index if params[:search].present? addresses = Addresses.near(params[:search], 25, :order =&gt; :distance) @profiles = Profile.where(:id =&gt; addresses.id) @title = "Therapists Near " + :search else @profiles = Profile.all @title = "Everyone" end end </code></pre> <p>Here's my models: </p> <pre><code>class Profile &lt; ActiveRecord::Base has_many :addresses, :dependent =&gt; :destroy accepts_nested_attributes_for :addresses, :reject_if =&gt; lambda { |a| a[:street].blank? }, :allow_destroy =&gt; true class Address &lt; ActiveRecord::Base belongs_to :profile geocoded_by :street after_validation :geocode, :if =&gt; :street_changed? </code></pre> <p>Thanks a lot for taking a look!</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