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

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

The Archive Base Latest Questions

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

I am encountering a routing error when I try to render a partial in

  • 0

I am encountering a routing error when I try to render a partial in an ajax call:

Routing Error

No route matches {:action=>"destroy", :controller=>"relationships", :user_id=>#<User id: 2, username: .....

Within my app, I have a list of followers for a user displayed on the profile page. Instead of paginating the followers, I would like to try to return the next offset of followers from the server through AJAX. My view already utilizes partials for displaying a list of these followers (limited to 5 records).

My goal is to use an AJAX call to return this partial with the next offset of records formated (I haven’t implemented the functionality to return offset records yet – I’m just trying to get the ajax working first). The partials work fine when I visit the profile page in my browser (and view the first 5 records), the error occurs when I make the AJAX call.

Here is the form in the view where the ajax call originates:

<%= form_tag user_relationships_path(@user), method: :get, remote: true do %>
    <%= submit_tag 'load more...' %>
<% end %>

Here is the route:

resources :users, only: [:index, :show, :new, :create, :edit, :update, :destroy] do
  resources :relationships, only: [:create, :destroy, :index]
end

Here is my controller action (relationships#index) which responds to the request:

def index
  @user = User.find_by_username(params[:user_id])
    respond_to do |format|
      format.js { render 'load_followers' }
  end
end

The load_followers.js.erb partial:

$('ul#followers').append("<%= render 'users/following_items', users: @user.followers %>")

The users/following_items.html.erb partial:

<% users.each do |user| %>
<li class="clearfix">
    <div class="box-gravatar pull-left">
       <%= link_to user do %>
       <%= gravatar_for user, 40 %>
       <% end %>
    </div>
    <div class="pull-right">
       <%= render 'relationships/follow', user: user %>
    </div>
    <%= link_to user.username, user %>
    <div class="box-author">joined <%= join_date_for user %></div>
</li>
<% end %>

And finally the relationships/follow.html.erb partial:

<% unless current_user?(user) %>
   <% if current_user.following? user %>
      <p><%= link_to 'unfollow', user_relationship_path(user), method: :delete, class: "btn" %></p>
   <% else %>
      <p><%= link_to 'follow', user_relationships_path(user), method: :post, class: "btn btn-primary" %></p>
   <% end %>
<% end %>

I have tracked down the offending code to the relationships/follow.html.erb partial. When that is removed, the ajax call works fine and the partial is appended to the end of the ul. Clearly it has to do with rails having an issue with the link_to to the relationships#destroy method – however, nothing I’ve tried seems to work.

Edit: Here are the results of running rake routes:

root        /                                                posts#index
            posts_test        /posts/test(.:format)                            posts#test
                submit        /submit(.:format)                                posts#new
                signup        /signup(.:format)                                users#new
                 login        /login(.:format)                                 sessions#new
                logout DELETE /logout(.:format)                                sessions#destroy
                 about        /about(.:format)                                 about#index
                search        /search(.:format)                                search#index
              sessions POST   /sessions(.:format)                              sessions#create
           new_session GET    /sessions/new(.:format)                          sessions#new
               session DELETE /sessions/:id(.:format)                          sessions#destroy
         post_comments POST   /posts/:post_id/comments(.:format)               comments#create
            post_votes POST   /posts/:post_id/votes(.:format)                  votes#create
                 posts GET    /posts(.:format)                                 posts#index
                       POST   /posts(.:format)                                 posts#create
              new_post GET    /posts/new(.:format)                             posts#new
                  post GET    /posts/:id(.:format)                             posts#show
    user_relationships GET    /users/:user_id/relationships(.:format)          relationships#index
                       POST   /users/:user_id/relationships(.:format)          relationships#create
 new_user_relationship GET    /users/:user_id/relationships/new(.:format)      relationships#new
edit_user_relationship GET    /users/:user_id/relationships/:id/edit(.:format) relationships#edit
     user_relationship GET    /users/:user_id/relationships/:id(.:format)      relationships#show
                       PUT    /users/:user_id/relationships/:id(.:format)      relationships#update
                       DELETE /users/:user_id/relationships/:id(.:format)      relationships#destroy
                 users GET    /users(.:format)                                 users#index
                       POST   /users(.:format)                                 users#create
              new_user GET    /users/new(.:format)                             users#new
             edit_user GET    /users/:id/edit(.:format)                        users#edit
                  user GET    /users/:id(.:format)                             users#show
                       PUT    /users/:id(.:format)                             users#update
                       DELETE /users/:id(.:format)                             users#destroy
            categories GET    /categories(.:format)                            categories#index
                       POST   /categories(.:format)                            categories#create
          new_category GET    /categories/new(.:format)                        categories#new
              category GET    /categories/:id(.:format)                        categories#show
                              /:category(.:format)                             posts#index

Thanks!

  • 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-17T01:59:41+00:00Added an answer on June 17, 2026 at 1:59 am

    Notices your rake routes outputted this line:

    DELETE /users/:user_id/relationships/:id(.:format)
    

    This means your named route user_relationship is expecting both user and relationship IDs. Reason being, relationship is a nested resource of user.

    So for instance you currently have this in your link to:

    = link_to 'unfollow', user_relationship_path(user), method: :delete, class: "btn"
    

    Instead it should be something like:

    = link_to 'unfollow', user_relationship_path(user, relationship), method: :delete, class: "btn"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been encountering a linker error when attempting to call a class method
I'm encountering an error sprintf statement. I added a printf command to help investigate,
I am encountering a very strange error with my project. I normally use the
I am encountering a very strange error for that says the following: Template is
I have been encountering this error for my project, which involves working with Digital
I am encountering a 403 Forbidden error when posting URL's via a form using
I am encountering the above error. The main script is under below #!/opt/lampp/bin/perl use
I am randomly encountering the following error: Message: Invalid viewstate. Client IP: xx.xxx.xxx.xx Port:
I am encountering this error whenever the button is clicked to collapse/expand the panel.
I am encountering a problem with codeigniter and JQuery Ajax Post. My javscript $('.remove').click(function(){

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.