Question

i tried to add the gem Geocoder to my App, but i can't figure out how i get the Geotagging to work.

My Model looks like this:

class Home < ActiveRecord::Base


  geocoded_by :full_street_address
  after_validation :geocode
end

And i my Form i added a field for full_street_adress

<%= form_for(@home) do |f| %>
    <%= text_field_tag :full_street_address %>
    <%= f.submit %>
<% end %>

When i try to add a new Home, I get the following error

undefined method `full_street_address' for #

Extracted source (around line #10):

def create
    home = Home.new(params[:home])
    home.save && home.home_memberships.create(:user => current_user, :owner => true)
end

def AddMember
Was it helpful?

Solution

You're using wrong key :home in params. Should be

def create
    home = Home.new(params[:full_street_address])
    home.save && home.home_memberships.create(:user => current_user, :owner => true)
end

BTW, in the form you missed f and label (if needed)

<%= form_for(@home) do |f| %>
    <%= f.label :full_street_address, "Home address" %>
    <%= f.text_field_tag :full_street_address %>
    <%= f.submit %>
<% end %>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top