I can't seem to find how a date or datetime gets to have (1i), (2i), etc. What method gives this? I'm asking because I have a gem that breaks this functionality in Rails, and I want to make a test for it, and fix it.
This is the new error that happens when I install the gem:
undefined method `published_at(1i)=' for #<Page:0xc25ccd4> (NoMethodError)
./app/controllers/admin/pages_controller.rb:21:in `update'
./vendor/plugins/exception_notification/lib/exception_notifier.rb:19:in `call'
./features/step_definitions/web_steps.rb:29
./features/step_definitions/web_steps.rb:14:in `with_scope'
./features/step_definitions/web_steps.rb:28:in `/^(?:|I )press "([^"]*)"(?: within "([^"]*)")?$/'
features/domain_linking.feature:11:in `And I press "Update page"'
You'd need to take a look into the Rails source code, starting from ActionView::Helpers::DateHelper module and digging further in to get to the appropriate function.
Related
Currently when I look in the log files of my rails application I get stacktraces like:
NoMethodError (undefined method `[]' for nil:NilClass):
app/controllers/concerns/example.rb:192:in `rescue in create_example'
app/controllers/concerns/example.rb:163:in `create_example'
app/controllers/concerns/example.rb:11:in `example'
app/controllers/example_controller.rb:39:in `create'
The error is triggered from a second project which is included as gem.
On line 192 in the example.rb (concern) we use some classes from that included gem and in that class the real exception occurs.
Another example:
ZeroDivisionError (divided by 0):
app/controllers/dummy_controller.rb:15:in `index'
And on line 15
test_object.divide_by_zero
test_object is an instance of a class defined in the included gem
I want rails to display and log the full stacktrace including all or specific gems but I can't figure out how to do this. Does someone know how to do this? or someone that can give me a push in the right direction?
Thanks!!!
It's used like this:
Rails.backtrace_cleaner.remove_silencers!
Depending on what version of rails you are using this may help:
http://api.rubyonrails.org/classes/ActiveSupport/BacktraceCleaner.html#method-i-remove_silencers-21
I'm working on a Ruby 1.8 / Rails 2.1 application which is connecting to a SQL Server 2008 database.
When I try to use a find_by_CompanyCode method, ActiveRecord returns a NoMethodError. Yet, from the following you can see that the table exists and has the method in question.
Not sure what I'm missing.. any help would be appreciated
EDIT: Only fields which end in "Code" aren't appearing when I just run IvantageEmployee.first .. error occurs from a view. Moving the exact same code to a controller, the code works as expected.
eval #goal.organization_type.employee_class + ".find_by_#{#goal.organization_type.employee_field_code}('#{#goal.specifier}').#{#goal.organization_type.employee_field_description}"
>> IvantageEmployee.first.CompanyCode
=> "GAI"
>> IvantageEmployee.find_by_CompanyCode('GAI')
NoMethodError: undefined method `find_by_CompanyCode' for IvantageEmployee(Table doesn't exist):Class
from /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/base.rb:1613:in `method_missing_without_paginate'
from /usr/lib/ruby/gems/1.8/gems/will_paginate-2.3.15/lib/will_paginate/finder.rb:170:in `method_missing'
from (irb):7
>>
Some more information. The table has several fields. The one I'm struggling with is CompanyCode, but it also has RegionDescription.
Note the following console output. find_by_RegionDescription works; find_by_CompanyCode doesn't work. Also, CompanyCode doesn't appear when I just output the class, but RegionDescription doesn't Not sure why ActiveRecord would be missing fields that are on the table
>> IvantageEmployee.find_by_RegionDescription 'GAI'
### Finding method find_by_RegionDescription
=> nil
>> IvantageEmployee.find_by_CompanyCode 'GAI'
### Finding method find_by_CompanyCode
NoMethodError: undefined method `find_by_CompanyCode' for IvantageEmployee(Table doesn't exist):Class
from /usr/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/base.rb:1614:in `method_missing_without_paginate'
from /usr/lib/ruby/gems/1.8/gems/will_paginate-2.3.15/lib/will_paginate/finder.rb:170:in `method_missing'
from (irb):9
>>
You need to use snake case instead of camel case:
IvantageEmployee.find_by_company_code('GAI')
The convention in ruby is to use camel case for classes and snake case for methods. Rails follows that convention(as should you) so you can assume that any methods dynamically created by it are going to be snake case.
i am using rails_admin. when i go to certain resource. by typin url
localhost:3000/admin/rule
than it give me this error. code is:
scope = Rule.all
scope.page(1).per(2)
. above code is writtten in rails_admin gem.in a file named mongoid.rb placed in adaptors folder. complete log is:
NoMethodError (undefined method `page' for #<Array:0xcea7408>):
mongoid (2.4.8) lib/mongoid/criteria.rb:385:in `method_missing'
/home/usman/.rvm/gems/ruby-1.9.2-p290#system/bundler/gems/kaminari-809105ad782a/lib/kaminari/models/mongoid_extension.rb:11:in `page'
/home/usman/.rvm/gems/ruby-1.9.2-p290#system/bundler/gems/rails_admin-069819944cc9/lib/rails_admin/adapters/mongoid.rb:37:in `all'
/home/usman/.rvm/gems/ruby-1.9.2-p290#system/bundler/gems/rails_admin-069819944cc9/app/controllers/rails_admin/main_controller.rb:127:in `get_collection'
/home/usman/.rvm/gems/ruby-1.9.2-p290#system/bundler/gems/rails_admin-069819944cc9/app/controllers/rails_admin/main_controller.rb:39:in `list_entries'
/home/usman/.rvm/gems/ruby-1.9.2-p290#system/bundler/gems/rails_admin-069819944cc9/lib/rails_admin/config/actions/index.rb:30:in `block (2 levels) in <class:Index>'
what should i do to resolve this error?
You can not call Kaminari methods on Array, because Rule.all will return Array.
So you have to do something like this: Rule.page(1).per(2)
Here is documentation and examples of Kaminari usage:
https://github.com/amatsuda/kaminari
I've been running into this issue off and on for a while now using Mongoid. Sometimes refreshing the page in RailsAdmin would fix it.
I figured out that the problem is Kaminari's hooks are not initialized in my environment, so the models that rely on Kaminari's extension methods don't have them available.
I simply took the following line from Kaminari's railtie and put it at the top of my rails_admin initializer:
Kaminari::Hooks.init
Now things seem to be working for me. However, I don't know why the ActiveSupport callback is not running that code.
Use this
Kaminari.paginate_array(Rule.all).page(params[:page])
Kader's solution is great! The only thing is I found I have to add .per to make it work.
Kaminari.paginate_array(Rule.all).page(params[:page]).per(PER_PAGE_RECORDS)
Looking at this solution https://github.com/tuupola/rack-facebook-method-fix it seems great except it omits what is probably obvious to most, but it's 5:30 in the morning and perhaps my brain is not working. In what file and where should I put the lines:
require "rack-facebook-method-fix"
use Rack::Facebook::MethodFix
? I assumed the top of application.rb but that gives me an error message:
/config/application.rb:5:in `<top (required)>': undefined method `use' for main:Object (NoMethodError)
Okay - so adding the above lines in the different environment files and modifyg the use line to read:
config.middleware.use Rack::Facebook::MethodFix
seems to work
Does anyone know why I get the following error when I use the web_step#follow method?
When I follow "Stuff" within "#main-nav" # features/step_definitions/web_steps.rb:33
undefined local variable or method `node' for #<Capybara::Driver::RackTest::Node:0x00000101409b40> (NameError)
./features/step_definitions/web_steps.rb:35:in `block (2 levels) in <top (required)>'
./features/step_definitions/web_steps.rb:14:in `block in with_scope'
./features/step_definitions/web_steps.rb:14:in `with_scope'
./features/step_definitions/web_steps.rb:34:in `/^(?:|I )follow "([^"]*)"(?: within "([^"]*)")?$/'
This is the html output:
<ul id='main-nav'>
<li>Things</li>
<li>Stuff</li>
</ul>
P.S. I have removed webrat and am solely using capybara
Thanks in advance!
per: https://github.com/jnicklas/capybara/issues/110
comment out this line in env.rb:
require 'cucumber/rails/capybara_javascript_emulation'
Note: after commenting that line you'll have to explicitly tag your features/scenarios with #javascript if you want to click links with onclick javascript handlers.
See also: https://github.com/aslakhellesoy/cucumber-rails/issues/77 which eventually takes you on a journey to discover it should be fixed in cucumber-rails v0.4.0 (2011-03-20). This may still be relevant for folks with Rails 2.3.x projects using cucumber-rails v0.3.2
This means that the actual output of your page does not include the element you're trying to search for. For example, if you had with_scope("#my_div") but your content didn't have any divs with the id my_div it would raise this exception.
I'd suggest trying to add a cucumber step of Then show me the page before the failing step, and investigate the source of the generated page.