开发者

How to make function in application_controller.rb visible in views?

开发者 https://www.devze.com 2023-02-13 12:23 出处:网络
In my application-controller.rb I did: def show_footer? 开发者_开发知识库@show_footer = true end

In my application-controller.rb I did:

def show_footer?
开发者_开发知识库   @show_footer = true
end

Then in my view I am getting an error saying show_footer? isn't defined.

note, this view is in another controller then inherits application_controller.


Controller methods are not in scope to views; only helper methods are. You can add a controller method as a helper also by doing the following:

class ApplicationController < ActionController::Base
  helper_method :show_footer?

  def show_footer?
    # Your method implementation.
  end
end

Now you'll be able to refer to show_footer? in both your controllers and your views.


Put it in application_helper.rb instead.

Also, you probably mean to have @show_footer == true instead of =.

0

精彩评论

暂无评论...
验证码 换一张
取 消