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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:20:11+00:00 2026-05-25T01:20:11+00:00

I have nested resources in my rails application which belong to groups. These items

  • 0

I have nested resources in my rails application which belong to groups. These items all have comments, and as such the comment file looks as follows:

app/models/comment.rb

class Comment < ActiveRecord::Base
    belongs_to :item, :polymorphic => true
    ...
end

I need an ActionMailer which sends the user a link to the item, nested within its specific group. This however has left me banging my head against the wall as how to get the full path into the URL for the link. This is because url_for, when given a polymorphic object calls polymorphic_url on the object, but does not path the options of :only_path => false as the polymorphic_url doesn’t take said option. Even in the non-nested resource (second link) it still only gives a path

Currently my mailer view looks as follows:

views/interaction_mailer/new_comment.html.erb

Hey <%= @user.name %>!<br />
<br />
<%= @comment.user.name %> just commented on the <%= @item_string %> <%=  link_to @item.title, polymorphic_path([@item.group, @item]) %> in your group (<%= link_to @item.group.name,  @item.group, :only_path => false%>).<br />

As I said, this doesn’t give me a full path, but instead just a relative one.

Am I missing something? Is there a way to easily get the full path in this email?

PS my config/environments/development.rb file has the following:

config.action_mailer.default_url_options = {:host => 'localhost', :port => 3000}
  • 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-05-25T01:20:12+00:00Added an answer on May 25, 2026 at 1:20 am

    I’m not sure if I’m understanding. Why is it a problem if polymorphic_url doesn’t accept :only_path? Don’t you want the full url in the email?

    Why not simply call polymorphic_url([@item.group, @item])?

    This should return the full URL, which is what you want, right?

    The 2nd link isn’t constructed correctly. You’re passing the object as the 2nd arg, and only_path as the 3rd, which is being interperted as HTML options. The ActionView url_for helper forces path when using polymorphic routes (the opposite of ActionController’s url_for… go figure), but you can simply call polymorphic_url to get at the URL in this case.

    <%= link_to @item.group.name, polymorphic_url(@item.group) %>
    

    … should give you the URL.

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

Sidebar

Related Questions

So In my rails app I have two resources (rentals, and reservations) which belong
I using the Rails resource_controller plugin. I have a ReleasesController, which is nested within
In Rails 3 edge, I have set up two nested resources like this: config/routes.rb
I'm using Rails 2. I have resources nested like this: - university_categories - universities
I have the following nested resources in my routes.rb file. The inner resource specifies
So I have a forum application and double nested resources. Section-->Topic-->Replies and are set
So I have a Rails 3.1 app that contains nested resources: resources :projects do
I have a Rails application that has a Company resource with a nested resource
I have a nested route in rails 3 mapped as resources :maps do resource
To set up nested resources in Rails, I have seen example routes given like

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.