Ruby On Rails اسئلة واجوبة المقابلات
Question: What is the purpose of YIELD in Ruby on Rails?Answer:The interpreter essentially invokes a separate piece of code and places it in the location. You might say it is similar to a method calling another method. Lets understand a little bit of background about where YIELD might be useful first. The Rails framework encourages you to write code that is DRY (Dont Repeat Yourself). Developers often write common code in a central file and then they write the custom code in the specific files. Lets say you are building a web application and you want all pages to have a common header, a common footer, the same Welcome user-name! message. You can put all this common code in your application.html.erb file. <html> .... common page title
.. standard header...
<body>
..common page title,
<%= YIELD %>
..footer code can go here... </body>
</html>
The rest of the custom code can go in your specific file. Say the page you are creating is the list of articles. Then in your implementation file you would just write the code for pulling in the articles and the final page displayed to the user would be your custom code which will be placed instead of the <%= YIELD %>code in the application.html.erb file. |
احفظ للمراجعة
احفظ هذا العنصر في الإشارات المرجعية، او حدده كصعب، او ضعه في مجموعة مراجعة.
سجل الدخول لحفظ الإشارات المرجعية والاسئلة الصعبة ومجموعات المراجعة.
الاكثر فائدة حسب تقييم المستخدمين:
- What is Ruby On Rails?
- Why Ruby on Rails?
- Explain how (almost) everything is an object in Ruby.
- What are Gems and which are some of your favorites?
- How would you declare and use a constructor in Ruby?