I'm having trouble rendering JSON with Rails 3.0. Whenever I visit the URL, nothing appears to show up on the screen (I'm pretty sure the JSON should be displaying kind of like XML?) Sorry, I'm fairly new to Rails in general
Here is my code.
def rjson
@comments = Chat.all
respond_to do |format|
format.json { render :json => @comments }
end
end
I simplified it as much as possible. Based on some of the tutorials I have
My routing looks like this:
match '/chatbox/rjson', :to => 'chatbox#rjson'
I'm pretty sure my model is fine.
I don't know if I should even have a 'rjson' view like (rjson.json.erb?) but I'm pretty sure I can just render from the controller without a view right?
If you are sure rjson
will only response with json
format, you just need:
def rjson
@comments = Chat.all
render :json => @comments
end