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 8823507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:22:25+00:00 2026-06-14T06:22:25+00:00

I’m currently working on a tour interface that guides new users around my site.

  • 0

I’m currently working on a tour interface that guides new users around my site. I have a Tour model that has many TourStops, each of which contains information about a section of the site.

Basically, I’d like to write a function for the Tour model that — when passed the number of a TourStop — generates the correct class and data attribute for the HTML element it’s attatched to. For example, I’d like

<%= link_to image_tag("new_button.png", tour.stop_data(1), :title => 'Add new asset'), new_asset_path %>

to call a function and return something like

def stop_data(order)
     " :class => '#{tour_stops.find_by_order(order).name}', 
       :data => '{:order => order}'"
end

creating a link_to tag like:

<%= link_to image_tag("new_button.png", :class => 'tour_stop_1', 
       :data => {:order => 1}, :title => 'Add new asset'), new_asset_path %>

The above code doesn’t work. Is something like this even possible? If not, what’s a better approach I might take?

  • 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-14T06:22:27+00:00Added an answer on June 14, 2026 at 6:22 am

    The image_tag accepts two parameters. A source, and a options Hash.

    What you are trying to do is squeezing your return value from stop_data into this options Hash.

    In order to get this to work, you first, need to return a Hash from stop_data, and second, make sure you pass only two arguments to image_tag – the source, and the options.

    First:

    def stop_data(order)
      { 
        :class => tour_stops.find_by_order(order).name, 
        :data  => { :order => order } # you may need order.to_json
      }
    end
    

    Second:

    link_to image_tag("new_button.png", tour.stop_data(1), :title => "Add new asset"), new_asset_path
    

    This looks like it will work, but it won’t, since your’e passing three parameters to image_tag.

    When you do the following:

    image_tag("new_button.png", :class => "tour_stop_1", :data => { :order => 1 }, :title => "Add new asset")
    

    It looks like you’re passing even 4 parameters to image_tag, but in fact they are only two. In Ruby, when the last parameter of a method is a Hash, you don’t need to wrap the Hash key/value pairs in curly braces ({}), so the example above is essentially the same as

    image_tag("new_button.png", { :class => "tour_stop_1", :data => { :order => 1 }, :title => "Add new asset" })
    

    Now, to get your helper to work with image_tag, you need to merge the options, so they become only one Hash.

    link_to image_tag("new_button.png", tour.stop_data(1).merge(:title => "Add new asset")), new_asset_path
    

    Again, we’re omitting the curly braces when calling merge, because it’s only (and therefore last) parameter is a Hash. The outcome is the same as:

    tour.stop_data(1).merge({ :title => "Add new asset" })
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I
I want use html5's new tag to play a wav file (currently only supported
I have an array which has BIG numbers and small numbers in it. I
I'm working with an upstream system that sometimes sends me text destined for HTML/XML

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.