Ruby on Rails webpacker asset_pack_path throws undefined method asset_path - ruby-on-rails

I'm working on a Ruby on Rails app that is using Webpacker. I get a strange undefined method error when using asset_pack_path - a NoMethodError is thrown and says undefined method 'asset_path' Did you mean? asset_pack_path. This is a similarly named method but not the one I am calling; asset_path does not appear in the app's codebase either.
I believe to be calling the correct path inside of asset_pack_path but that does not seem to be consistent with the error. Perhaps there is a versioning mis-match somewhere? I am at a loss with this one. Any ideas or suggestions to resolve this undefined method error and use asset_pack_path would be helpful.
Thanks!

You are trying to call Rails Views helper method inside a Controller.
Try: ActionController::Base.helpers.asset_pack_path

It turned out that asset_path was called inside the asset_pack_path method - both ActionView::Helpers::AssetUrlHelper Webpacker::Helper need to be included for asset_pack_path to work

Related

how to use gem doc_ripper with external links

So I am trying to use the doc_ripper gem and as per whats written all the requirements work fine.
What I am trying to implement is that instead of path to local file, I would like to include path to url of the file.
When I tried to run the command --> DocRipper::rip('/path/to/file')
for the external link it gave me the following error
DocRipper::rip(s3storageurl)
NoMethodError: undefined method `rip' for nil:NilClass
I would like to know if anybody is using the above gem and is able to pass urls

Ruby on Rails - undefined local variable or method - wice grid haml show_code

I am new to ruby on rails.
I am trying to get haml and wice_grid to work together. I am using this example as a model:
http://wicegrid.herokuapp.com/basics3
I get the error 'undefined local variable or method `show_code' for...'
In the file app/views/basics3/index.html.haml which you can see at the link above.
Am I missing a gem? In general, what is the best way to troubleshoot problems like this?
Thanks in advance-
Flex
EDIT: I found the definition for show_code. It's in a helper that I found in the unit tests for wice_grid.
https://github.com/leikind/wice_grid_testbed/blob/master/app/helpers/application_helper.rb
That said, I get more errors when I load it into my project. So the question becomes, how does the helper normally get included in my project?
show_code is a custom method created just for the example page you linked to. It just displays the code he has in his controller and his index and grid views. You don't need to call that method in your own application so just remove that line and you should be good.

My Controller can't find my (Action)Mailer!

Greeting all...
I'm trying to figure out a problem that I've never seen and shouldn't be happening by all accounts...
I'm using Rails 3.0.12 with a simple/standard ActionMailer setup:
I have HelpRequestMailer in app/mailers
I have HelpRequestsController in app/controllers
First problem... When I call the mailer in my controller...
help_request = HelpRequest.new(params[:help_request])
...
HelpRequestMailer.help_request_email(help_request).deliver
I get the following error: NameError (uninitialized constant HelpRequestsController::HelpRequestMailer)
This in itself is strange.
When I add the following...
require File.expand_path('../../mailers/help_request_mailer', FILE)
...To the top of the controller (I would expect the path to be '../mailers/help_request_mailer' but that doesn't work) - which I shouldn't have to do - the controller seems to find the mailer but doesn't seem to recognize what it is/know what to do with it. I get the following error:
NoMethodError (undefined method `help_request_email' for HelpRequestMailer:Class)
Which is technically true... There's no help_request_email class method in HelpRequestMailer... It's an instance method (as specified by the documentation).
My ActionMailer configuration lives in config/application.rb
Any help/suggestions would be greatly appreciated...
I had this problem too, and it turned out to be a case of a completely unhelpful error message. In my case it was just a syntax error in some of my code for the action mailer or the associated view.
I think what happened is that when Rails couldn't properly parse the mailer or view code, it just bypassed the files and never instantiated the action mailer object, leading to the error in the controller.
I would have much preferred it if Rails had tripped on the error in the action mailer code itself.

Facebooker2 template issue

When i include fb_connect_async_js javascript helper it is throwing an
error , Facebooker 2 don't have action view template. Could you please tell
me how handle this situation .
undefined local variable or method `fb_connect_async_js' for
ActionView::Base
Thanks,
Srini
try add require 'facebooker2' in environment.rb and rake gems:install

Using link_to_remote inside of a controller

how can I use link_to_remote inside of a controller?
I have already included ActionView::Helpers::JavaScriptHelper, but still get the error:
undefined method `content_tag'
Thanks!
You'll need to discover all of the helpers that need to be included to make it work. For instance, content_tag is part of ActionView::Helpers::TagHelper.
http://www.railsbrain.com/api/rails-2.2.2/doc/index.html?a=M002139&name=content_tag
It may be time to consider an alternative design.

Resources