Reputation:
Hello guys I am developing an application with ruby on rails I want to render partial on ajax success Here is the action of the controller
def re
@question = Question.find_by_title(params[:qt])
respond_to do |re|
re.js {}
end
end
And here is my re.js.erb:
document.getElementById("details").value = "<%= @question.details %>";
document.getElementById("tag").value ="<%= @question.tag %>";
var ansForm =document.getElementById("new_answer");
ansForm.action=" http://localhost:3000/questions/<%= @question.id %>/answers" ;
document.getElementById("txt_title").innerHTML = "<%[email protected] %>";
document.getElementById("txt_tag").innerHTML = "<%[email protected] %>";
$(".answers").empty();
$(".answers").append("<h1>Added Answers</h1>");
$(".answers").append("<%= render @question.answers %>");
But I am getting this error :
GET http://localhost:3000/re?qt=Can%20I%20add%20anything%20to%20water? 500 (Internal Server Error)
Upvotes: 1
Views: 260
Reputation: 76774
Your code looks okay, but there'll be a problem which isn't shown publicly:
Right-Click
>Inspect Element
>Network
- When you send the request, click on the new item that shows
- It should appear red -- click onto it & click on
preview
- See what the "real" error is
The problem you'll have will likely be down to an error within your code (either Rails or JS). The only way to know for sure is to show the rendered error message in your development console
Try this:
#controller
def re
@question = Question.find_by_title(params[:qt])
respond_to do |format|
format.js
end
end
#re.js.erb
alert("hello");
Upvotes: 0
Reputation: 2617
Check your serverlog (log/development.log) as there should be more information there than just the "500 Internal" that the browser gives you.
How does your config/routes.rb look like? (perhaps it doesnt accept GET to /re)
Upvotes: 1