-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to access controller methods in erb file? #116
Comments
Hm, my Ruby is rusty... module MyAwesomeHelpers
module Controller # I don't know what this line does
def print_some_stuff
return 'some stuff'
end
end Should this not be: module MyAwesomeHelpers
module Controller
def Controller.print_some_stuff
return 'some stuff'
end
end
end |
Ya module MyAwesomeHelpers
module Controller
def self.print_some_stuff
# Do you need `return`?
return 'some stuff'
end
# or
# Not sure if this works in module (that's is not a class)
class << self
def print_some_stuff
# Do you need `return`?
return 'some stuff'
end
end
end
end |
@rhys-vdw The controller is set up correctly, I redacted the details of the controller and made a mistake with the nesting when writing it here, thanks for catching that! But my Ruby is very rust right now as well 😅 @PikachuEXE I can give that a try, thanks! One thing to note about this controller is that its methods are used in a "regular" view file at |
Well controller instances are only created in response to a request, so they won't exist at build time. This is why I was trying to make sense of your code example. Anything that is global should be available to rails-erb-loader. An easy way to test if this is true is to open up the Rails REPL and see if your Ruby works. If your code works there then it should work in the template. |
I have a controller at
lib/my_awesome_helpers/controller.rb
that looks something like this:I set up my
webpack.config.js
file with the following options:And here is my
frontend/lib/testing.js.erb
file:My setup works great, however, when I try to access any of my controller methods, I get the following error when I run my webpack build:
Any idea on how to get this working?
The text was updated successfully, but these errors were encountered: