0

I need to try this helper method in rails console, but I get an error I'm sorry I'm a newbie en rails

juan:~/workspace/sample_app$ rails c
Loading development environment (Rails 4.2.0.beta2)
2.1.1 :001 > helper.provide(:title,"Home")
 => nil 
2.1.1 :002 > yield :title
LocalJumpError: no block given (yield)

I want to reproduce the behavior in rails console of the view helper method called provide

Example

 <% provide(:title, "Home") %>
<!DOCTYPE html>
<html>
  <head>
    <title><%= yield(:title) %> | Ruby on Rails Tutorial Sample App</title>
  </head>
  <body>
    <h1>Sample App</h1>
    <p>
      This is the home page for the
      <a href="http://www.railstutorial.org/">Ruby on Rails Tutorial</a>
      sample application.
    </p>
  </body>
</html>
user3678471
  • 2,373
  • 2
  • 17
  • 18
  • *I need to try this helper method in rails console,* Can you explain why you need to do that? – 7stud Oct 24 '14 at 06:23

1 Answers1

1

You can use yield only when you are inside a method which has been called with a block. In the rails console, you are in the main environment and without any block which is why you get that error.

You can take a look at this answer to find out how yield works in the view.

The best way to do what you're trying to do is to put a debugger inside the view while its rendering and then test out the provided functionality.

Community
  • 1
  • 1
Zero Fiber
  • 4,417
  • 2
  • 23
  • 34