ActionController::UnknownFormat
Update the create
action as below:
def create
...
respond_to do |format|
if @reservation.save
format.html do
redirect_to '/'
end
format.json { render json: @reservation.to_json }
else
format.html { render 'new'} ## Specify the format in which you are rendering "new" page
format.json { render json: @reservation.errors } ## You might want to specify a json format as well
end
end
end
You are using respond_to
method but anot specifying the format in which a new
page is rendered. Hence, the error ActionController::UnknownFormat
.
ActionController::UnknownFormat in StocksController#search
Shouldn't you target #results
instead of #result
like
$('#results').html("<%=j (render 'users/result.html')%>")
Rails ActionController::UnknownFormat error with respond_to
For one, you're still specifying instance variables after your implicit call to render
(in the respond_to
block). Those instance variable declarations should be above any rendering.
Also, I've seen this happen in some browsers. You can get around it by declaring a dummy render block for the html
type, so something like:
respond_to do |format|
format.html { render(:text => "not implemented") }
format.js
end
The html
format block will likely never get called, but its declared nonetheless.
ActionController::UnknownFormat in Controller ( #index)
Well, after going around testing a wide range of ideas, I came back to my original thought and it worked perfectly. I don't know what went wrong the first time but now it is perfect.
Related Topics
Case Statement With Multiple Values in Each 'When' Block
Query , Can Not Select Column Count
How to Pass Arguments into a Rake Task With Environment in Rails
Rvm and Thin, Root Vs. Local User
How to Change My Ruby Version Using Rvm
Creating Microsoft Word (.Docx) Documents in Ruby
In Ruby How to Overload the Initialize Constructor
Accessing Elements of Nested Hashes in Ruby
What Do 'I' and '-I' in Regex Mean
How to Keep the Delimiters When Splitting a Ruby String
Measure the Distance Between Two Strings With Ruby
Cannot Install Json Gem in Rails Using Windows
Printing the Source Code of a Ruby Block
Is the Ruby Operator ||= Intelligent
How to Install a Gem or Update Rubygems If It Fails With a Permissions Error