config.action_controller.asset_path_template -- undefined method? - ruby-on-rails

I'm trying to use:
https://github.com/polleverywhere/asset_fingerprinter
To install for Rails 3 you need to set:
config.action_controller.asset_path_template = AssetFingerprinter.path_rewriter
But that errors with:
.rvm/gems/ruby-1.9.2-p180#andyw/gems/actionpack-3.0.5/lib/action_controller/railtie.rb:54:in `block (3 levels) in <class:Railtie>': undefined method `asset_path_template=' for ActionController::Base:Class (NoMethodError)
Any ideas?
Thanks

I believe asset_path_template is not a method but a member in a hash
Try config.action_controller["asset_path_template"]

Related

Testing Shrine gem return error undefined method `set_derivatives'

I am trying to test uploads through Shrine.
I have Minio and followed this tutorial https://shrinerb.com/docs/testing#test-data
Yet FactoryBot.lint returns the following error from the TestModule code provided in the link:
profilepic - undefined method `set_derivatives' for #<Shrine::Attacher:0x000055ee893dfe00 #file=#<Shrine::UploadedFile storage=:store id="8aa14e79342fde0077fd48f1035f56c3" metadata={"size"=>576152, "mime_type"=>"image/jpeg", "filename"=>"profile_pic.jpg"}>, #cache=:cache, #store=:store, #context={}, #previous=nil, #column_serializer=Shrine::Plugins::Column::JsonSerializer, #model_cache=true, #model=nil, #destroy_block=nil, #promote_block=nil, #errors=[]> (NoMethodError)
# /home/maxence/.rvm/gems/ruby-3.0.3/gems/factory_bot-6.2.1/lib/factory_bot/linter.rb:13:in `lint!'
# /home/maxence/.rvm/gems/ruby-3.0.3/gems/factory_bot-6.2.1/lib/factory_bot.rb:70:in `lint'
# ./spec/support/factory_bot.rb:7:in `block (2 levels) in <top (required)>'
Any idea what's wrong ?
Just from the error it looks like derivatives plugin is not loaded. https://shrinerb.com/docs/plugins/derivatives
Add this to the test module
Shrine.plugin :derivatives

Rails test giving me an error of "undefined method 'body' "

I am writing tests for my rails application. I wrote tests when I finished the user model for my project. The tests were working fine when I wrote them a few months back, however, I am getting the same error on 15 different tests. The errors are given below.
1) Error:
UserTest#test_email_should_be_present:
NoMethodError: undefined method `body' for #<User:0x00000008c84238>
test/models/user_test.rb:21:in `block in <class:UserTest>'
2) Error:
UserTest#test_should_be_valid:
NoMethodError: undefined method `body' for #<User:0x00000008caebf0>
test/models/user_test.rb:11:in `block in <class:UserTest>'
3) Error:
UserTest#test_name_should_not_be_too_long:
NoMethodError: undefined method `body' for #<User:0x00000008cb5068>
test/models/user_test.rb:26:in `block in <class:UserTest>'
4) Error:
UserTest#test_associated_scoreboards_should_be_destroyed:
NoMethodError: undefined method `body' for #<User:0x00000008cc2650>
test/models/user_test.rb:69:in `block in <class:UserTest>'
5) Error:
UserTest#test_email_addresses_should_be_unique:
NoMethodError: undefined method `body' for #<User:0x00000008cce4f0>
test/models/user_test.rb:55:in `block in <class:UserTest>'
6) Error:
UserTest#test_email_validation_should_accept_valid_addresses:
NoMethodError: undefined method `body' for #<User:0x00000008cdf318>
test/models/user_test.rb:39:in `block (2 levels) in <class:UserTest>'
test/models/user_test.rb:37:in `each'
test/models/user_test.rb:37:in `block in <class:UserTest>'
7) Error:
UserTest#test_email_validation_should_reject_invalid_addresses:
NoMethodError: undefined method `body' for #<User:0x00000008ce4c28>
test/models/user_test.rb:48:in `block (2 levels) in <class:UserTest>'
test/models/user_test.rb:46:in `each'
test/models/user_test.rb:46:in `block in <class:UserTest>'
8) Error:
UserTest#test_email_should_not_be_too_long:
NoMethodError: undefined method `body' for #<User:0x00000008cf2508>
test/models/user_test.rb:31:in `block in <class:UserTest>'
9) Error:
UserTest#test_name_should_be_present:
NoMethodError: undefined method `body' for #<User:0x00000008cfff78>
test/models/user_test.rb:16:in `block in <class:UserTest>'
10) Error:
UserTest#test_password_should_have_a_minimum_length:
NoMethodError: undefined method `body' for #<User:0x00000008d05b08>
test/models/user_test.rb:61:in `block in <class:UserTest>'
11) Error:
PasswordResetsTest#test_passwords_resets:
NoMethodError: undefined method `body' for #<User:0x000000061021a0>
app/controllers/password_resets_controller.rb:29:in `update'
test/integration/password_resets_test.rb:50:in `block in <class:PasswordResetsTest>'
12) Error:
UsersEditTest#test_successful_edits_with_friendly_forwarding:
NoMethodError: undefined method `body' for #<User:0x000000085088b0>
app/controllers/users_controller.rb:44:in `update'
test/integration/users_edit_test.rb:28:in `block in <class:UsersEditTest>'
13) Error:
UsersEditTest#test_unsuccessful_edits:
NoMethodError: undefined method `body' for #<User:0x000000082a6798>
app/controllers/users_controller.rb:44:in `update'
test/integration/users_edit_test.rb:13:in `block in <class:UsersEditTest>'
14) Error:
UsersSignupTest#test_Invalid_sign-up_submission:
NoMethodError: undefined method `body' for #<User:0x000000063cb9b8>
app/controllers/users_controller.rb:29:in `create'
test/integration/users_signup_test.rb:12:in `block (2 levels) in <class:UsersSignupTest>'
test/integration/users_signup_test.rb:11:in `block in <class:UsersSignupTest>'
15) Error:
UsersSignupTest#test_valid_sign-up_information_with_account_activation:
NoMethodError: undefined method `body' for #<User:0x0000000600c340>
app/controllers/users_controller.rb:29:in `create'
test/integration/users_signup_test.rb:26:in `block (2 levels) in <class:UsersSignupTest>'
test/integration/users_signup_test.rb:25:in `block in <class:UsersSignupTest>'
The error I get is a NoMehtodError: undefined method 'body', I am sure the problem isn't in the code. There must be a common denominator associated with all these errors. I get ZERO failures in my tests. I am not sure where this error is coming from. I don't have a method body anywhere in the code. The fixtures are not seeding any data into the test application. The code for the first few tests is given below.
test "email should be present" do
#user.email = " "
assert_not #user.valid?
end
test "should be valid" do
assert #user.valid?
end
test "name should not be too long" do
#user.name = "a" * 51
assert_not #user.valid?
end
I didn't include all the test code for all the error for the sake of keeping it brief and to the point. I wasn't exactly sure what code to include to help solve the problem. If any additional code is required please feel free to ask. As always, any help would be greatly appreciated.
Thanks
When we generate a model by using rails generate or rails g scaffolding command, it will invoke tasks and create some related files for us. One of the files is test/fixtures/...yml.
For example:
one:
user: one
body: MyText
two:
user: two
body: MyText
In ActiveSupport::TestCase class at test/test_helper.rb, the setup all fixtures method fixtures :all is called when we run tests. We have to modify the fixtures to follow the model attributes. If there is a mismatch between a model and the fixture, it will raise an error. In this problem, I believe there is a mismatch between User model attributes in the table and user fixture in test/fixtures/users.yml. Otherwise, please check another autogenerated fixture. There might be a body: MyText in the .yml file.
Hope it will help someone who faces the same problem

NoMethodError: undefined method `create_reset_digest' for #<User:0x007fba32e0af58>

I got these 5 errors upon doing a bundle rake exec test. I have no idea how to resolve it. I've googled and googled with no end in site (see what I did there). Now I turn to you for help!
If you accept, these are the errors:
1) Error:
PasswordResetsTest#test_password_resets:
NoMethodError: undefined method `create_reset_digest' for #<User:0x007fba32e0af58>
app/controllers/password_resets_controller.rb:12:in `create'
test/integration/password_resets_test.rb:17:in `block in <class:PasswordResetsTest>'
2) Error:
UsersLoginTest#test_login_with_valid_information_followed_by_logout:
ActionView::Template::Error: undefined method `current_user?' for #<#<Class:0x007fba2cdf19a0>:0x007fba28cd32c0>
app/views/microposts/_micropost.html.erb:10:in `_app_views_microposts__micropost_html_erb___3978616761423832463_70218762096200'
app/views/users/show.html.erb:15:in `_app_views_users_show_html_erb___2170813965465965459_70218768032700'
test/integration/users_login_test.rb:14:in `block in <class:UsersLoginTest>'
3) Error:
UsersProfileTest#test_profile_display:
ActionView::Template::Error: undefined method `current_user?' for #<#<Class:0x007fba2cdf19a0>:0x007fba2f8c51e0>
app/views/microposts/_micropost.html.erb:10:in `_app_views_microposts__micropost_html_erb___3978616761423832463_70218762096200'
app/views/users/show.html.erb:15:in `_app_views_users_show_html_erb___2170813965465965459_70218768032700'
test/integration/users_profile_test.rb:11:in `block in <class:UsersProfileTest>'
4) Error:
UsersIndexTest#test_index_as_admin_including_pagination_and_delete_links:
ActionView::Template::Error: undefined method `current_user?' for #<#<Class:0x007fba2cdf19a0>:0x007fba28ed08e8>
app/views/users/_user.html.erb:4:in `_app_views_users__user_html_erb__3013593760514997339_70218798383040'
app/views/users/index.html.erb:7:in `_app_views_users_index_html_erb___1851646122892737362_70218763684120'
test/integration/users_index_test.rb:12:in `block in <class:UsersIndexTest>'
5) Error:
MicropostsInterfaceTest#test_micropost_interface:
ActionView::Template::Error: undefined method `current_user?' for #<#<Class:0x007fba312ac360>:0x007fba2ff66120>
app/views/microposts/_micropost.html.erb:10:in `_app_views_microposts__micropost_html_erb___3978616761423832463_70218762096200'
app/views/shared/_feed.html.erb:3:in `_app_views_shared__feed_html_erb___1999510692289199836_70218832039180'
app/views/static_pages/home.html.erb:13:in `_app_views_static_pages_home_html_erb__315324690869897794_70218832802580'
test/integration/microposts_interface_test.rb:11:in `block in <class:MicropostsInterfaceTest>'
BACKSTORY: I ignored these errors messages as I went through a few of the chapters. I'm not sure if it popped up between 9, 10, or 11. I am new to programming so I don't know if this is enough information for you to be able to help me. The deeper I get into programming material the more it all seems confusing. SOS
I suppose you are following the https://www.railstutorial.org
You have a recurring undefined method 'current_user' error in [2, 3, 4, 5]
Did you defined the current_user helper method as it should be done in your session_helper.rb ?

WEBRIck not booting up..getting error message

Here is the new error message I am getting when doing rails s....
Exiting
C:/Sites/ThinkBlog/crumblr/config/initializers/devise.rb:235:in block
in <top (required)>': undefined method[]' for nil:NilClass
(NoMethodError) from
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/devise-3.3.0/lib/devise.rb:292:in
setup' from
C:/Sites/ThinkBlog/crumblr/config/initializers/devise.rb:3:in<top
(required)>' from
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:241:in `load'
By the way line 235 in device.rb is ,
config.omniauth :facebook, FACEBOOK_CONFIG['facebook_api_key'], FACEBOOK_CONFIG['facebook_api_secret']
The error messages tells you exactly what is wrong with your code: undefined method[]' for nil or in other words: You try to call the [] method on an object the is nil.
Since you only call [] on FACEBOOK_CONFIG the only reason for this errors is: FACEBOOK_CONFIG is not initialized and therefore nil.

NoMethodError: undefined method new for nil:NilClass

I’m facing a problem when trying to enter the list = list.new in the rails console. I get the following error message:
NoMethodError: undefined method `new’ for nil:NilClass
from /Users/csamanian/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.8/lib/active_support/whiny_nil.rb:48:in `method_missing’
from (irb):1
from /Users/csamanian/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.8/lib/rails/commands/console.rb:44:in `start’
from /Users/csamanian/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.8/lib/rails/commands/console.rb:8:in `start’
from /Users/csamanian/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.8/lib/rails/commands.rb:23:in `’
from script/rails:6:in `require’
from script/rails:6:in `’
Any ideas why?
Thanks a lot!
Model names are capitalized by convention in Rails. Try this instead:
list = List.new
You should try this
#list = List.new

Resources