G.frege를 너무 사랑하는 holy가...

[rails] frequently used functions

[ document summary ]
    Title: [rails] frequently used functions
    date: 2023 8.2
    content: 예전 자료 정리중.

Frequently used Functions

Provide & yield function

test할 때 주로 사용되는 function이다. view의 경우 controller에서 값이 넘어와서 처리하는 경우가 많다. 이것을 테스트 할때 provide와 yield를 같이 사용한다. 예를 들어보자.

 <% provide(:title, “About”) %>
 <html>
    <head>
         <title> <%= yield(:title) %> | Ruby on Rails Tutorial Sample App</title>
    </head>
    …
</html>

link_to는 메뉴판에 메뉴를 나타낸다. 즉 link를 나타내는데, 형식은 다음과 같다. button도 메뉴가 될 수 있다. class에 button을 추가하면 버튼도 메뉴다. 이미지도 메뉴가 될 수 있다. image_tag를 내부 인자로 가지면 된다. image_tag는 단지 이미지 resource를 나타낼 뿐이다.

<%= link_to “sample app”, ‘#’> <%= link_to “Sign up now!”, ‘#’, class: “btn btn-lg bt-primary” %> <%= link_to image_tag(“rails.png”, alt: “Rails logo”), “http://rubytutorials.org ” %>