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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:40:31+00:00 2026-06-11T01:40:31+00:00

Solution While on 1.8, i couldnt use the accepted answer directly, but it helped

  • 0

Solution

While on 1.8, i couldnt use the accepted answer directly, but it helped me find the below:

def stylesheet_include(*sources)
  if /^3\.[1-2]/ =~ Rails.version && sources.last.is_a?(Hash)
    sources.last.delete :cache
  end
  stylesheet_link_tag *sources
end

Original question

Working on a modified stylesheet_link_tag helper to pass things properly depending on the rails version, as this map maybe be loaded as an engine in Rails 3.1.x. Here’s my code so far, and what i’d like to do:

def stylesheet_include(*sources)
  options = sources.extract_options!.stringify_keys
  if /^3\.[1-2]/ =~ Rails.version
    options.delete "cache"
  end
  stylesheet_link_tag *sources, options
end

The problem is, I cannot pass a second parameter when i call * on the sources variable. I cannot just pass sources, options either, because the link_tag method requires several parameters, not an array. If it receives an array, then you get paths such as: css/reset/css/main.css

Anyone have ideas on how I can get this to work. Worse case scenario I can just not pass the options to it, but i’d rather avoid that.

  • 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-11T01:40:33+00:00Added an answer on June 11, 2026 at 1:40 am

    Actually, if you’re using Ruby 1.9, you can indeed have splats before other parameters. Like so:

    def stylesheet_include(*sources, options)
      options = sources.extract_options!.stringify_keys
      if /^3\.[1-2]/ =~ Rails.version
        options.delete "cache"
      end
      stylesheet_link_tag *sources, options
    end
    

    The problem, of course, is that the last thing you pass to this method will then always become options, even if it isn’t a hash. And you can’t assign a default to options either, since that behavior would be fairly ambiguous. Thus that solution will work if you always make sure to at least pass an empty hash as the last parameter of stylesheet_include.

    If that doesn’t work for you, try taking the splat as the parameter and seeing if the last member of the splat is a hash: if so it’s your options, if not your options are empty.

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

Sidebar

Related Questions

I've been searching a solution for a while but couldn't find any. I do
i was searching for a while, but couldn't find a fitting solution: My Case:
I've searched on here for a while but can't find a solution that works.
I was searching for a while but i couldn't find the solution. Situation: I'm
I have seen the solution to this a while back, but can't seem to
I've got this problem for a while now and I cannot find a solution
I've been pondering this problem for a while and can't find the solution (It
I've been looking for quite a while already and still couldn't find a solution
Ok I tried to google it but couldn't find a solution so I am
I am currently trying to set up a new visual studio 2008 solution while

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.