Reputation: 505
I have a controller
class UserController < ApplicationController
def add
@post = Post.new
end
def f(title)
Something
end
end
I want call a method f from add page
<%= f(Hello) %>
But I get an error :
undefined method `f'
Upvotes: 1
Views: 52
Reputation: 5905
You have to write this method on the user_helper.rb
file to access that on view.
or, You can use that code,
class MyController < ApplicationController
def my_method
# Lots of stuff
end
helper_method :my_method
end
Upvotes: 2
Reputation: 5251
Define f as helper method:
class UserController < ApplicationController
def add
@post = Post.new
end
def f(title)
Something
end
helper_method :f
end
Upvotes: 2