Search code examples
ruby-on-railsruby-on-rails-3.2simple-formgmaps4rails

Need Help Rails 3.2.3 -Pre-populating User data into simple_form for book resource passed into gmaps4rails to render marker into map.


thanks for reading, I need help;

scenario: User registers onto website, entering in their "address" ex. San Francisco, CA -gmaps4rails then does it's magic & it shows in the user profile show view -user location -San Francisco. {Not displaying map here}

Displaying map on book show. User can upload a book -I'm using Simple_form {do I add a hidden field here with @user.address? -sorry confused, did this & it didn't work.}

So then if I put in the show view Location <%= @book.user.address %> -it shows San Francisco.

But, on the map below -nothing shows up.

How do I get the 2 to interlink? So that people don't have to spend time filling in their location, if it's already associated with their account? Do I have to render an association for user address & book address for simple_form, but then how do I make that work correctly in the gmaps4rails.

Also, was looking at people using JS to render the marker, would you recommend that? I'd like to use purely server-side though -as I want to use Ajax to submit the book form & display in an index with maybe hover over to display the map.

Looking forward to your responses, as I've been stuck on it.


Solution

  • You can either set the @book address in the controller, or set the default value in the view. eg:

    @book.address ||= @book.user.address