L
L
lavezzi12015-08-20 08:17:55
Ruby on Rails
lavezzi1, 2015-08-20 08:17:55

How to set a method globally?

Hello.
I can't get this line to work on the page /views/applications.html.haml
%h1.name #{@user.first_name} #{ @user.last_name}
On the pages users/show.html.haml it works.
How to set a method so that it works everywhere, on all pages?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Kirill Bobykin, 2015-08-20
@Qelphybox

You need to declare the method as a helper.

class ApplicationController < ActionController::Base
helper :show_user
   def show_user
       #блаблабла
   end
end

T
thepry, 2015-08-20
@thepry

I can't get this line to work in /views/applications.html.haml

It's worth writing the error message you get when "can't force".
Wangyu that @user is not defined for you.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question