SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Aug 2006
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Newbie has NoMethodError following a turorial. Help Please!!

    Hello all,

    I have been following along with the apple developers tutorial on ruby on rails http://developer.apple.com/tools/rubyonrails.html and I am running into a NoMethodError. I am wondering if there is a typo in their code, or if I am doing somehting wrong. I run into problems about three quarters of the way through the tutorial in the "Adding Business Logic" part that deals with helpers. I am unable to get the "Total" number at the bottom. I just get the NoMethodError. Any help on this would greatly be appreciated. I been scratching my head for a while now. My code is below along with the full trace. Thanks to anyone who can help me escape my coding hell and see the light at the end of the tunnel.

    NoMethodError in Expenses#show

    Showing app/views/expenses/show.rhtml where line #20 raised:

    private method `total_expenses' called for #<Account:0x2248a30>
    Extracted source (around line #20):

    17: </tr>
    18: <tr>
    19: <td align="right" colspan="3">
    20: <strong>Total</strong>: <%= total(@account) %>
    21: </td>
    22: </tr>
    23: <% end %>
    RAILS_ROOT: /Users/adam/expenses/public/../config/..

    Application Trace | Framework Trace | Full Trace
    /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/base.rb:1792:in `method_missing'
    #{RAILS_ROOT}/app/helpers/expenses_helper.rb:4:in `total'
    #{RAILS_ROOT}/app/views/expenses/show.rhtml:20:in `_run_rhtml_expenses_show'
    #{RAILS_ROOT}/app/views/expenses/show.rhtml:12:in `each'
    /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/associations/association_proxy.rb:110:in `send'
    /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/associations/association_proxy.rb:110:in `method_missing'
    /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/associations/has_many_association.rb:90:in `method_missing'
    #{RAILS_ROOT}/app/views/expenses/show.rhtml:12:in `_run_rhtml_expenses_show'
    /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_view/base.rb:316:in `send'
    /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_view/base.rb:316:in `compile_and_render_template'
    /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_view/base.rb:292:in `render_template'
    /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_view/base.rb:251:in `render_file'
    /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/base.rb:726:in `render_file'
    /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/base.rb:648:in `render_with_no_layout'
    /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/layout.rb:245:in `render_without_benchmark'
    /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/benchmarking.rb:53:in `render'
    /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/benchmarking.rb:53:in `measure'
    /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/benchmarking.rb:53:in `render'
    /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/base.rb:942:in `perform_action_without_filters'
    /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/filters.rb:368:in `perform_action_without_benchmark'
    /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/benchmarking.rb:69:in `perform_action_without_rescue'
    /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/benchmarking.rb:69:in `measure'
    /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/benchmarking.rb:69:in `perform_action_without_rescue'
    /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/rescue.rb:82:in `perform_action'
    /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/base.rb:408:in `send'
    /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/base.rb:408:in `process_without_filters'
    /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/filters.rb:377:in `process_without_session_management_support'
    /usr/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/session_management.rb:117:in `process'
    /usr/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/dispatcher.rb:38:in `dispatch'
    /usr/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/fcgi_handler.rb:150:in `process_request'
    /usr/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/fcgi_handler.rb:54:in `process!'
    /usr/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/fcgi_handler.rb:53:in `each_cgi'
    /usr/lib/ruby/gems/1.8/gems/fcgi-0.8.7/lib/fcgi.rb:609:in `each'
    /usr/lib/ruby/gems/1.8/gems/fcgi-0.8.7/lib/fcgi.rb:609:in `each_cgi'
    /usr/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/fcgi_handler.rb:53:in `process!'
    /usr/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/fcgi_handler.rb:23:in `process!'
    /Users/adam/expenses/public/dispatch.fcgi:24

  2. #2
    SitePoint Zealot
    Join Date
    Jul 2005
    Posts
    124
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What does your app/helpers/expenses_helper.rb look like, did you add the total method?

  3. #3
    SitePoint Addict
    Join Date
    Mar 2005
    Posts
    251
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It looks like the problem is the total_expenses method in your app/models/account.rb
    Can you post the code from that file?

  4. #4
    SitePoint Evangelist
    Join Date
    Feb 2006
    Location
    Worcs. UK
    Posts
    404
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think the solution may be simpler than you think. Rails is case sensitive. The clue is in the first few lines of the error message

    NoMethodError in Expenses#show
    Is showing a method problem in a contoller called "Expenses".

    Showing app/views/expenses/show.rhtml where line #20 raised
    This line shows that the controller is called "expenses". In a case sensitive world "Expenses" is different to "expenses".

    Easy mistake to make. I recognise the error, because I make the mistake so often myself.

    In general, always use lower case in Rails URLs. The correct URL should be something like:

    http://localhost:3000/expenses/show

  5. #5
    SitePoint Guru silver trophy Luke Redpath's Avatar
    Join Date
    Mar 2003
    Location
    London
    Posts
    794
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ReggieB - that doesn't seem like the issue.

    It seems that the total() helper method is trying to call a private method on the Account object, total_expenses(). Thats the problem.

  6. #6
    SitePoint Evangelist
    Join Date
    Feb 2006
    Location
    Worcs. UK
    Posts
    404
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Luke, you are right.

    I've just had a play with one of my applications. I get a method missing error when I put a path /controller/View, instead of /controller/view, but not if I enter /Controller/view. Also when you make this error it shows up on the line:
    Showing app/views/expenses/show.rhtml where line #20 raised:
    rather than in the earlier line. For example it would be:
    Showing app/views/expenses/Show.rhtml where line #20 raised:
    Ignore my post.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •