Gettin 500 Internal server error in rails on ajax request

I am trying to create a post from a form. I used railscast 136 for ground work. When I try to submit, I get 500 errors for partial missing. I created a correlated javascript view of the controller, but it requests a view with the same name as the model.

error message

Submitted appointments /create.js.erb (3.8ms) Completed 500 internal Server error in 12ms

ActionView :: Template :: Error (Missing partial assignments / assignment with {: locale => [: en] ,: formats => [: js ,: html] ,: handlers => [: erb ,: builder ,: coffee] }. Search: * "/ Users / gjores / Sites / Rails / verkstad_test / app / views"): 1: $ ('# meetings'). Append ('<% = j render (@appointment)%>'); App / views / destination / create.js.erb: 1: in _app_views_appointments_create_js_erb___2325925946390315228_70273089113920' app/controllers/appointments_controller.rb:16:in

create

controller

 def create
    @appointment = Appointment.new(params[:appointment])
    if @appointment.save
      respond_to do |format|
        format.html { redirect_to new_appointment_path, :notice => "Successfully created appointment." }
        format.js
      end
    else
      render :action => 'new'
    end
  end

      

<strong> assignments /new.html.erb

<div id="appointments">
    <%= render 'shared/appointment_part' %>
</div>
<% title "New Appointment" %>
<table>
<% @students.each do |s| %>
<%= form_for @appointment,  :remote => true do |f|%>
  <%= f.error_messages %>
  <tr>  
    <td><%= s.name %></td>
    <td><%= f.label :week %></td>
    <td><%= f.number_field :week %></td>
    <td><%= f.label :teacher_id %></td>
    <td><%= f.collection_select(:teacher_id, Teacher.all, :id, :name) %></td>
    <%= f.hidden_field :student_id, :value => s.id %>

  <td><%= f.submit %></td>
  </tr>
<% end %>
<% end -%>
</table>

<p><%= link_to "Back to List", appointments_path %></p>

      

<strong> assignments /create.js.erb

$('#appointments').append('<%= j render(@appointment) %>');

      

Routes

    appointments GET    /appointments(.:format)          appointments#index
                 POST   /appointments(.:format)          appointments#create
 new_appointment GET    /appointments/new(.:format)      appointments#new
edit_appointment GET    /appointments/:id/edit(.:format) appointments#edit
     appointment GET    /appointments/:id(.:format)      appointments#show
                 PUT    /appointments/:id(.:format)      appointments#update
                 DELETE /appointments/:id(.:format)      appointments#destroy
        teachers GET    /teachers(.:format)              teachers#index
                 POST   /teachers(.:format)              teachers#create
     new_teacher GET    /teachers/new(.:format)          teachers#new
    edit_teacher GET    /teachers/:id/edit(.:format)     teachers#edit
         teacher GET    /teachers/:id(.:format)          teachers#show
                 PUT    /teachers/:id(.:format)          teachers#update
                 DELETE /teachers/:id(.:format)          teachers#destroy
 notice_students POST   /students/notice(.:format)       students#notice
        students GET    /students(.:format)              students#index
                 POST   /students(.:format)              students#create
     new_student GET    /students/new(.:format)          students#new
    edit_student GET    /students/:id/edit(.:format)     students#edit
         student GET    /students/:id(.:format)          students#show
                 PUT    /students/:id(.:format)          students#update
                 DELETE /students/:id(.:format)          students#destroy

      

+3


source to share


2 answers


Your stack trace displays

Missing partial appointments/appointment

      

So it looks like rails are trying to display partial name of .html appointments / appointments or .js appointments / appointments

Is there a file called assignments.js.erb or assignments.html.erb?

If not, then create it.



I however suspect that what you are trying to do is show your purpose as I think you want the code below to update the html of some element on your page.

$('#appointments').append('<%= j render(@appointment) %>');

      

I think you need this line for red

$('#appointments').append('<%= j render :partial => 'appointments/appointment', :formats => :html %>');

      

Your private html view should be assignment / _appointment.html.erb

+5


source


This is because you are presenting the /new.html.erb assignment partial in the view , not the create method in the controller .



Since the partial is defined in the tasksments / new.html.erb view , so the corresponding javascript view should be assignments / new.js.erb .

+1


source







All Articles