Rails Controllers

Controllers are an important part of every mvc framework and in Rails also it is like other mvc frameworks which is the logical center for your application. In Rails a controller is a Ruby is class with one or methods.

To create a class in Ruby write keyword “class” followed by class and no need of braces or curly braces. to end the class just simply type “end”.

The general syntax of creating a Ruby class is as follows:

class ClassName

... Your code...

end

To create a controller in Rails either you can do it manually or you can use rails command. By doing it manually in your project simple go to /app/controllers and create a new file (this file is usually a Ruby class) with the extension of .rb or by using rails commands open cmd and go to your project folder type

rails generate controller ControllerName

in here ControllerName can be any name you like. This commands also generate a view folder with same name as your controller name under /app/views

Leave a Reply

Your email address will not be published.

Wordpress Social Share Plugin powered by Ultimatelysocial