Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8437291
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T07:23:27+00:00 2026-06-10T07:23:27+00:00

I am not experiencing errors locally but am on Heroku. Error is: ‘ActionView::Template::Error (undefined

  • 0

I am not experiencing errors locally but am on Heroku. Error is:

‘ActionView::Template::Error (undefined method `each’ for nil:NilClass)’

The ‘each’ is referring to each i in @position in the <% for i in @positions %> line of my User callback.html.erb view below:

<% for i in @positions %>
<strong>
<% begin %>
<%= @user.positions.find_by_id(i).title + " at " %>
<% rescue %>
<% end %>

<% begin %>
<%= @user.positions.find_by_id(i).company %>
<% rescue %>
<% end %>
</strong>

Here is the relevant portion of my auth controller (callback section)

def callback

...

    @user = current_user

...

    #positions
    for i in 0..(positions.count-1)

      begin
        @company_i = companies[i]['name']
      rescue
      end

      begin
        @title_i = positions[i]['title']
      rescue
      end

      begin
        @industry_i = companies[i]['industry']
      rescue
      end

      begin
        @start_month_i = positions[i]['start-date']['month']
        @start_year_i = positions[i]['start-date']['year']
      rescue
      end

      begin
        @end_month_i = positions[i]['end-date']['month']
        @end_year_i = positions[i]['end-date']['year']
      rescue
      end

      begin
        @li_pos_id_i = positions[i]['id']
      rescue
      end

      if Position.find_by_li_pos_id(@li_pos_id_i).nil?
        @user.positions.build(li_pos_id: @li_pos_id_i, company: @company_i, title: @title_i, 
          industry: @industry_i, start_month: @start_month_i, start_year: @start_year_i, 
          end_month: @end_month_i, end_year: @end_year_i)
      end
    end

    @user.save
    @positions = @user.positions.map(&:id)
end

I think it has something to do with my .find_by methods returning a nil value, but I’m not sure how to fix it. Thank you!

EDITED AUTH CONTROLLER:

positions.each do |position|
      begin
        @li_pos_id = position.id
        @title = position.title
        @company = position.company.name
        @industry = position.company.industry
        @start_month = position.start_date.month
        @start_year = position.start_date.year
        @end_month = position.end_date.month
        @end_year = position.end_date.year
      rescue
      end

      unless Position.find_by_li_pos_id(@li_pos_id)
        current_user.positions.build(li_pos_id: @li_pos_id, title: @title, company: @company, industry: @industry, 
          start_month: @start_month, start_year: @start_year, end_month: @end_month, end_year: @end_year)
      end

      @user.save
      @user.positions.save
    end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T07:23:28+00:00Added an answer on June 10, 2026 at 7:23 am

    What you’re doing here is called “Pokemon Exception Handling” since you catch all exceptions and throw them in the trash. This is a very bad habit to develop and leads to enormous amounts of frustration if you’re working on a team with other developers since it hides unexpected errors and makes debugging significantly harder because you will never get a proper stack trace when in those sections you’ve walled off.

    Instead of blindly catching exceptions, you should be catching specific, expected exceptions where applicable, and only where they could possibly be raised. You should also make every effort to avoid generating them in the first place.

    An example of this would be:

    <% @position_ids.present? and @position_ids.each do |position_id| %>
    

    Calling your position variable i is also very poor style as names of that sort are generally reserved for increments or indexes, nothing more. Using a slightly longer but more descriptive name helps immeasurably.

    You’re also using this very peculiar for x in y notation for loops where Ruby encourages the use of the more succinct y.each do |x| version.

    Further, testing for nil? rather than just testing for the object itself is almost always redundant and can be eliminated. The nil? test is only relevant when you want to distinguish between false and nil which are the only two non-true values in Ruby. In this case a simple unless (x) is better than if (x.nil?).

    As to why you’re not getting anything in @positions, this is probably because the callback routine is not running in the first place. From the look of things, unless there’s a return somewhere in there, then that value must be assigned at the end of the routine.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I do not know why I am experiencing this error. Actually content place holders
i am experiencing following error while trying to run application on heroku 2011-06-03T11:24:25-07:00 heroku[nginx]:
I'm experiencing this error... variable 'paymentLine' of type 'Xrm.sb_directdebitpaymentline' referenced from scope '', but
from today I've been experiencing an issue with Google Maps resulting into not centering
I've been experimenting with programming Facebook apps and Heroku. It's still not clear to
Not ever sure if it can be done, but is it possible to use
Not to sound like a koan, but just wondering if there are definite rules
We are using Rails 2.3.5 and have been experiencing seemingly random Timeout::Error: execution expired
We're trying to migrate a .Net 3.5 solution into .Net 4.0, but are experiencing
We're experiencing errors when someone tries to send an email using non-English characters (á

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.