does not find rjs file
I am using rails 2.3.8 and I'll load a modal dialog box using a partial called _show_venue.html.erb. Inside this partial I add link_to_remote to edit each venue.
_show_venue.html.erb ::
<table>
<tr>
<th>Country</th>
<th>Place</th>
<th>Color</th>
</tr>
<% @venues.each do |venue| %>
<tr>
<td><%=h venue.country_id %></td>
<td><%=h venue.place %></td>
<td><%=h venue.color %></td>
<td><%= link_to_remote 'Edit', :url => {:controller => 'venues', :action => 'edit', :id=>venue.id } %></td>
</tr>
<% end %>
</table>
And this is my controller code ::
def edit
@venue = Venue.find(params[:id])
end
edit.js.rjs ::
page.replace_html 'edit_venue', :partial => '开发者_运维技巧edit_form'
page<< "$j ('#event_actions').dialog({
title: 'Edit venue
modal: true,
width: 500,
close: function(event, ui) { $j ('#event_actions').dialog('destroy') }
});"
But when I run this, it could not find edit.js.rjs file. Why did this happen? Anyone can explain it?
You should do the following changes to you controller method:
respond_to do |format|
format.js
end
so that it will find the edit.js.rjs and render it.
Edit: The 404 HTTP status which was the main problem was because of a missing route.
A route to match venues/:id/edit should solve the problem.
Rename your file edit.js.rjs
to edit.rjs
Edited
I think you have to do it other way as you want dynamic object @venue
,
Try following
def edit
@venue = Venue.find(params[:id])
render :update do |page|
page.replace_html 'edit_venue', :partial => 'edit_form', :object => @venue
page<< "$j ('#event_actions').dialog({
title: 'Edit venue
modal: true,
width: 500,
close: function(event, ui) { $j ('#event_actions').dialog('destroy') }
});"
end
end
your link should be as follows [you have to write :method
]
<%= link_to_remote 'Edit', :url => {:controller => 'venues', :action => 'edit', :id=>venue.id }, :method=>'put' %>
you can also try 'post' if above doesn't work
rename edit.js.rjs to edit.js.erb
Add the following to the end of your edit method:
respond_to do |format|
format.js
format.html
end
restart your server
精彩评论