Czesc. Jestem jeszcze troche ciemny w railsach, ale cos tam sobie strugam. Na stronie mam formularz, ktory wykorzystuje autouzupelniajace sie field’y z plugina geolokacyjnego. Wyglada tak:
<% form_tag(:action => "add_point", :id => @user.id) do |format| %>
<%= error_messages_for(:point) %>
<p>
<%= label :point,"street","Street" -%><br />
<%= street_field :point, "street" %>
</p>
<p>
<%= label :point,"locality","Locality" -%><br />
<%= locality_field :point, "locality" %>
</p>
<p>
<%= label :point,"city","City" -%><br />
<%= city_field :point, "city" %>
</p>
<p>
<%= label :point,"state","State" -%><br />
<%= state_field :point, "state" %>
</p>
<p style="margin-right: 0px">
<%= label :point,"country","Country Name" -%><br />
<%= country_name_field :point, "country" %>
</p>
<p>
<%= label :point,"message","Message" %><br />
<%= text_area :point,"message", :class => 'message', :maxlength => 130 %>
</p>
<br />
<p class="button">
<%= submit_tag 'Save', :class => 'button' %>
</p>
<% end >
Moje pytanie: jak powinienem skonstruowac formularz, aby dane mogly sie dodac na strone bez reloadu, za pomoca js? W controllerze chcialbym wykorzystac respond to - format.js. Probowalem to robic przy pomocy form_remote_tag i czytalem api.rubyonrails.org, ale albo nie moge sobie poradzic za bardzo ze skladnia albo cos jest nie tak z routingiem, bo zawsze zamiast odswiezac strone, wyskakuje blad i tekstowo wyswietlany jest kod js (badz strona sie reloaduje, bez uzycia js)
Tak wyglada moj add_point.js.rjs:
page.insert_html :top, ‘put_it_here’, :partial => @new_point
page.visual_effect :highlight, “new_point”, :duration => 5, :startcolor => ‘#5555ff’
A tak kluczowe routesy:
map.resources :points
map.root :controller => 'public', :action => 'index'
map.add_point '/private/add_point/:id', :controller => 'user', :action => 'add_point'