codingdraculasbrain codingdraculasbrain - 10 months ago 701
Ruby Question

missing a template for this request format and variant

I am new to Ruby on Rails and am trying to gain a strong understanding of how MVC works.

I did the following:

rails new bubblesman
rails generate controller bubble

in my bubble controller I created a method as follows:

def available
puts "YEP!!!!!!"

I put the following in my routes file:

'welcome' => 'bubble#available'

I navigate to http://localhost:3000/welcome
I get the below error:

ActionController::UnknownFormat (BubbleController#available is missing a template for this request format and variant.

request.formats: ["text/html"]
request.variant: []

NOTE! For XHR/Ajax or API requests, this action would normally respond with 204 No Content: an empty white screen. Since you're loading it in a web browser, we assume that you expected to actually render a template, not… nothing, so we're showing an error to be extra-clear. If you expect 204 No Content, carry on. That's what you'll get from an XHR or API request. Give it a shot.):

what I also don't understand is if I put this in my helper controller instead of my main controller it all works fine.

Answer Source

you need to create the available.html.erb file within the views/bubble/ directory. When the route takes you to that action, it also navigates you to that view, so if you put:


as the only line in that file, it should return that to you on the webpage.

In the future, you could use rails g scaffold bubbles and that will create a majority of the files (MVC) and routes for you.