简体   繁体   中英

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!!!!!!"
end

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.

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:

<h2>YEP!!!!</h2>

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM