Claudiu S
Claudiu S

Reputation: 1627

Rails JQuery Missing template. Render Show action in Index

I have an rails app. I am starting to implement jquery functions within the app.

I have a Project model which has many Milestones. I am trying to render a partial of the Show action of my Milestones, in the Index action using JQuery. Unfortunately, I am unable to do so, due to the following error in my JS console:

GET http://localhost:3000/projects/1/milestones/1 500 (Internal Server Error) 

Missing template milestones/show_milestone,application/show_milestone with 
{:locale=>[:en], :formats=>[:js, :html], :handlers=>[:erb, :builder, :raw, 
 :ruby,  :jbuilder, :coffee]}

Controller show action

def show
    @milestone = Milestone.find(params[:id])
    respond_to do |format|
        format.js {render :show_milestone}
    end
end

javascripts/milestones/show_milestone.js

$(document).ready(function() {
  $(".milestone-content-area").html("<%=escape_javascript( render( :partial =>  "milestones/show_milestone", :locals=>{:@milestone=>@milestone} ))%>");
});

views/milestones/_show_milestone.html.erb

 <%= @milestone.title %> 

index.html.erb

<%= link_to milestone.title, project_milestone_path(@project, milestone), remote: true %>
<div class="milestone-content-area">
</div>

I don't seem to understand what I am doing wrong. Thanks for reading!

EDIT: I have added my link_to helper from my index.

Upvotes: 0

Views: 334

Answers (1)

Claudiu S
Claudiu S

Reputation: 1627

Credits go to @Sabyasachi Ghosh

I simply had to add the .erb extension to my show_milestone.js and move it into my views folder.

Upvotes: 0

Related Questions