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

  • SEARCH
  • Home
  • 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 9295725
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T21:40:26+00:00 2026-06-18T21:40:26+00:00

In my Rails app, I have projects that have many steps, and each step

  • 0

In my Rails app, I have projects that have many steps, and each step has many images.

I’m trying to tag links to pages about each step with information about the step, particularly the name of the step and the default image associated with the step.

<%= link_to "", project_step_path(@project, i), :class=> "dot", 
data: {title: steps.find_by_number(i).name, 
image: steps.find_by_number(i).images.order("position ASC").first.file} %>

The title data tag does return the name of the step, but I’m getting an error with my image data tag. When I try it in the rails console, it returns the file path to the image, but when I try to implement it in my app, I get the error undefined method `file’ for nil:NilClass.

When I remove “file” from my image tag (so it’s image: steps.find_by_number(i).images.order(“position ASC”).first), and I return what the image data tag is for each link, I get [object Object].

How can I get it to return the right query result?

Here is my steps controller:

class StepsController < ApplicationController

  before_filter :get_project

  def show
    @step = @project.steps.find_by_number(params[:id])
    @image = Image.new
    @images = @step.images.order("position")
    @steps = @project.steps.order("number")
    @numSteps = @steps.count

    respond_to do |format|
      format.html # show.html.erb
      format.json { render :json => @step }
    end
  end
  private
  # get_project converts the project_id given by the routing
  # into an @project object
  def get_project
    @project = Project.find(params[:project_id])
  end
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-18T21:40:28+00:00Added an answer on June 18, 2026 at 9:40 pm

    reason for this is the following entire thing becomes nil

    images.order("position ASC").first
    

    most possible problem might be is when you select steps by i, there can be a dataset which doesnot have images

    to avoid getting this error, one thing you could do is use try

    steps.find_by_number(i).images.order("position ASC").first.try(:file)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In a Rails 3.2 app I have a model Project, which has many Tasks.
So I have a Rails 3.1 app that contains nested resources: resources :projects do
I have a simple time-tracking app, that has projects, tasks, and entries. The setup
I have two projects on my computer: - An old Rails 2.3 app that
I have a rails app that makes web api call , the rails app
I have two databases in my app. One is Projects, that holds data on
I have a simple rails app with models project and phase. A project has
I have a Rails project that uses bundler. Many of the gems I'm included
I have a Rails app and I am trying to test it. I use
I have a Rails web app which has static files under dynamic restful urls.

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.