Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • views in ruby

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 306
    Comment on it

    Hello friends, I hope you all are doing well, so today I would be discussing rails view in ruby in rails. View in ruby is used to display the data which is requested by controller from web with the help of shareable variables. We usually end view file by erb, which stands for embedded ruby.

    you must have seen a folder named view and inside that there are several files which generate automatically at the time you generate controller and define methods inside controllers.

    we create .erb file inside views for each method we define in the controller so that it can collect information from specific method and can pass it to view for further rendering. let me explain you with the perfect example let's say you are creating a new app in rails

         rails new_app
        

    after that you will generate controller to write method for an application

         rails g controller articles index
        

    don't get confused with index here, it is used to automatically generate index.html.erb file in views folder. so what we have learned so far is.

    1. if you want rails to generate views automatically then you can define method name while generating controller.

    2. if you want to do it manually then you can just create erb file inside views folder by specifying it with the same name as you have specified inside a controller.

    Inside the html.erb file we will write ruby code in ruby snippets <%= %>. and here '=' is used if you want to display the content in a browser.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: