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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T21:50:20+00:00 2026-06-07T21:50:20+00:00

I have resource bio and in views and link for add new bio is:

  • 0

I have resource bio and in views and link for add new bio is:

= link_to "Add new bio", [:new, :admin, :bio]

If I put resource :bio to scope like this:

namespace :admin do    
  scope "/:bio_type", :defaults => {:bio_type => "company"} do
    resources :bios
  end
end

This doesn’t work

= link_to "Add new bio", [:new, :admin, :bio, { bio_type: params[:bio_type] }]

My question is how can I add scoped param to url_for helper? And can rails do this by default?

p.s. new_admin_bio_path({bio_type: params[:bio_type]}) works fine, but it’s just curious

  • 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-07T21:50:21+00:00Added an answer on June 7, 2026 at 9:50 pm

    I believe you cannot make this with array params to link_to. You have to use polymorphic_path or new_admin_bio_path({bio_type: params[:bio_type]})

    The reason is that link_to calls url_for with [:new, :admin, :bio, { bio_type: params[:bio_type] }], which calls polymorphic_path with these params.

    Check the source code for url_for and for polymorphic_url.
    Notice, that polymorphic_url takes 2 params – record_or_hash_or_array and options, but url_for calls it with one parameter only.

      def url_for(options = {})
        options ||= {}
        case options
        when String
          options
        when Hash
          options = options.symbolize_keys.reverse_merge!(:only_path => options[:host].nil?)
          super
        when :back
          controller.request.env["HTTP_REFERER"] || 'javascript:history.back()'
        else
          polymorphic_path(options)
        end
      end
    
    
      def polymorphic_path(record_or_hash_or_array, options = {})
        polymorphic_url(record_or_hash_or_array, options.merge(:routing_type => :path))
      end
    
      def polymorphic_url(record_or_hash_or_array, options = {})
        if record_or_hash_or_array.kind_of?(Array)
          record_or_hash_or_array = record_or_hash_or_array.compact
          if record_or_hash_or_array.first.is_a?(ActionDispatch::Routing::RoutesProxy)
            proxy = record_or_hash_or_array.shift
          end
          record_or_hash_or_array = record_or_hash_or_array[0] if record_or_hash_or_array.size == 1
        end
    
        record = extract_record(record_or_hash_or_array)
        record = convert_to_model(record)
    
        args = Array === record_or_hash_or_array ?
          record_or_hash_or_array.dup :
          [ record_or_hash_or_array ]
    
        inflection = if options[:action] && options[:action].to_s == "new"
          args.pop
          :singular
        elsif (record.respond_to?(:persisted?) && !record.persisted?)
          args.pop
          :plural
        elsif record.is_a?(Class)
          args.pop
          :plural
        else
          :singular
        end
    
        args.delete_if {|arg| arg.is_a?(Symbol) || arg.is_a?(String)}
        named_route = build_named_route_call(record_or_hash_or_array, inflection, options)
    
        url_options = options.except(:action, :routing_type)
        unless url_options.empty?
          args.last.kind_of?(Hash) ? args.last.merge!(url_options) : args << url_options
        end
    
        args.collect! { |a| convert_to_model(a) }
    
        (proxy || self).send(named_route, *args)
      end
    

    So, correct call with the scope option should sound like

    polymorphic_path([:new, :admin, :bio], bio_type: params[:bio_type])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a resource :products in a namespace :shop, like this: namespace :shop do
I have this resource allocator class public class ResourceAllocator { ArrayList<Request> queue = new
I have a resource that is a . This means my url looks like
Consider that I have 1 resource and 2 urls (let's say new one and
I have a resource file in the App_GlobalResources folder and i would like to
I have a resource file(.RES) and i want to add it into an existing
I have a resource file in a Class Library project. I'm using this resource
I have a resource declared in XAML like so: <Window x:Class=Test.MainWindow xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml xmlns:local=clr-namespace:Test
I have this model class User include DataMapper::Resource include BCrypt property :id, Serial property
[Edit: The solution to this problem is in the routes.rb file. I have resource

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.