Rails - javascript not reloading divs via remote call -


i trying create timeline user can create events go on timeline. i've had working fine in past, have since updated version of rails 3.2.14, , no longer works. possibly syntactical error if has changed between versions, or have done wrong?

the timeline show view renders partials including timeline, , create/edit/destroy form partials events. understand it, form getting submitted, , should calling create.js.erb.

what happening when click 'create event', contents of page replaced standard "event created" notice (not 1 create.js.erb), , else disappears. event has been created though. can help?

timeline show view:

<div id="show-timeline"> <%= render :partial => "show_timeline" %> </div>  <div class="content-box timeline-box">     <div id="my-timeline-box">         <%= render :partial => "my_timeline" %>     </div> <br />  <button id="new-event-button" class="btn btn-success btn-large">new event</button> <button id="edit-events-button" class="btn btn-info btn-large">edit events</button> <button id="delete-events-button" class="btn btn-danger btn-large">delete events</button>  <div id="events-forms">     <div id="new-event">         <%= render :partial => "new_event", :locals => { :event => event.new(:timeline_id=>@timeline.id) }, :remote => true %>     </div>      <div id="edit-events">         <%= render :partial => "edit_events", :locals => { :events => current_user.events }, :remote => true %>      </div>      <div id="delete_events">         <%= render :partial => "delete_events", :locals => { :events => current_user.events } %>             </div> </div> <div id="events-forms-edit">&nbsp;</div>  </div> 

events/create.js.erb

$('#new-event').html('<%= escape_javascript( render :partial => "/timelines/new_event", :locals => { :event => event.new(:timeline_id=>@timeline.id) }, :remote => true ) %>'); $('.notice').html("<p>event created.</p>"); $('.notice').show(300); $('#my-timeline-box').html('<%= escape_javascript( render :partial => "/timelines/my_timeline" ) %>'); $('#show-timeline').html('<%= escape_javascript( render :partial => "/timelines/show_timeline" ) %>'); $('#edit-events').html('<%= escape_javascript( render :partial => "/timelines/edit_events", :locals => { :events => current_user.events }, :remote => true ) %>'); $('#delete_events').html('<%= escape_javascript( render :partial => "/timelines/delete_events", :locals => { :events => current_user.events } ) %>'); 

events controller create action:

def create     @event = event.new(params[:event])     @timeline = current_user.timeline      respond_to |format|       if @event.save         format.html { redirect_to @event.timeline, notice: 'event created.' }         format.json { render json: @event, status: :created, location: @event }         format.js        else         format.html { render action: "new" }         format.json { render json: @event.errors, status: :unprocessable_entity }         format.js        end     end   end 

any appreciated!

update:

_new_event.html.erb

<br /> <h2>add event</h2> <h4>fill in form , click 'create event' add new event timeline.</h4>  <%= form_for(event, :remote => true) |f| %>   <% if event.errors.any? %>     <div id="error_explanation">       <h2><%= pluralize(event.errors.count, "error") %> prohibited event being saved:</h2>        <ul>       <% event.errors.full_messages.each |msg| %>         <li><%= msg %></li>       <% end %>       </ul>     </div>   <% end %>     <%=f.hidden_field 'timeline_id', :value => current_user.timeline.id %>   <div class="field">     <%= f.label :date %><br />     <%= f.date_select :start_date, :order => [:day, :month, :year], :start_year => 1800 %>   </div>   <div class="field">     <%= f.label :title %><br />     <%= f.text_field :headline, :size => 50 %>   </div>   <div class="field">     <%= f.label :event_description %><br />     <%= f.text_area :text, :size => "47x4" %>   </div>   <%= check_box_tag "blockcheck", :value => "1", :checked => false %>   <div class="field" id="media_box">     <%= f.label :media %>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span>please paste url here</span><br />     <%= f.text_field :media, :size => 50 %>   </div>   <div class="field">     <%= f.label :media_description %><br />     <%= f.text_area :caption, :size => "47x3" %>   </div>   <div class="actions">     <%= f.submit 'create event', :class => "btn btn-success"  %>   </div> <% end %> 

console output (when "create event" clicked):

started post "/events" 127.0.0.1 @ 2013-08-07 15:07:03 +0100 processing eventscontroller#create js   parameters: {"utf8"=>"v", "authenticity_token"=>"ppqntswha1veotzaenrtl7uhtq8wc f6c2/azmdga/ue=", "event"=>{"timeline_id"=>"4", "start_date(3i)"=>"7", "start_da te(2i)"=>"8", "start_date(1i)"=>"2013", "headline"=>"", "text"=>"", "media"=>"",  "caption"=>""}, "commit"=>"create event"}   ←[1m←[36muser load (5.0ms)←[0m  ←[1mselect "users".* "users" "users "."id" = 2 limit 1←[0m   ←[1m←[35mtimeline load (15.0ms)←[0m  select "timelines".* "timelines" whe re "timelines"."id" = 4 limit 1   ←[1m←[36mtimeline load (38.0ms)←[0m  ←[1mselect "timelines".* "timelines"  "timelines"."user_id" = 2 limit 1←[0m   ←[1m←[35m (0.0ms)←[0m  begin transaction   ←[1m←[36msql (6.0ms)←[0m  ←[1minsert "events" ("caption", "created_at", " credit", "end_date", "headline", "media", "start_date", "text", "thumbnail", "ti meline_id", "updated_at") values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)←[0m  [["capti on", ""], ["created_at", wed, 07 aug 2013 14:07:04 utc +00:00], ["credit", nil],  ["end_date", nil], ["headline", ""], ["media", ""], ["start_date", wed, 07 aug 2013], ["text", ""], ["thumbnail", nil], ["timeline_id", 4], ["updated_at", wed,  07 aug 2013 14:07:04 utc +00:00]]   ←[1m←[35m (171.0ms)←[0m  commit transaction   rendered timelines/_new_event.html.erb (15.0ms)   rendered timelines/_my_timeline.html.erb (0.0ms)   rendered timelines/_show_timeline.html.erb (0.0ms)   ←[1m←[36mevent load (30.0ms)←[0m  ←[1mselect "events".* "events" inner jo in "timelines" on "events"."timeline_id" = "timelines"."id" "timelines"."u ser_id" = 2←[0m   rendered timelines/_edit_events.html.erb (41.0ms)   rendered timelines/_delete_events.html.erb (3.0ms)   rendered events/create.js.erb (5123.3ms) completed 200 ok in 7899ms (views: 7538.4ms | activerecord: 265.0ms) 

however, nothing getting rendered.

check if have following lines in top of application.js.coffee:

#= require jquery #= require jquery_ujs 

if you're not using coffee, lines should same starting //=.

it seems you're not requiring rails unobtrusive javascript library, form post treated html instead of js.

if have dependency covered, provide code javascript files related issue?


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -