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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:01:40+00:00 2026-06-14T22:01:40+00:00

Very new to ruby on rails and trying to get my first ajax call

  • 0

Very new to ruby on rails and trying to get my first ajax call working. It is making the ajax call, but it always calls the #index action and seems to ignore the URL parameter. Here’s the code:

class UserController < ApplicationController
def flag
    logger.debug "in flag user"
    respond_to do |format|
      format.js { render :layout=>false }
    end
  end
end

In my routes.db:

resources :users do
    member do
      post 'flag'
      get 'flag'
    end
  end

And then in my view I create the link like this:

<%= link_to "Flag User", :url => flag_user_path(user.id), :method => :get, :remote => true %>

the HTML source is:

<a href="/users?method=get&amp;url=%2Fusers%2F1%2Fflag" data-remote="true">Flag User</a>

rake routes produces this:

flag_user  POST   /users/:id/flag(.:format)   users#flag
           GET    /users/:id/flag(.:format)   users#flag

Whenever I click on the link, the user#index method always gets executed. How do I get the user#flag method to execute?

  • 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-14T22:01:41+00:00Added an answer on June 14, 2026 at 10:01 pm

    The issue was the :url symbol. I changed:

    <%= link_to "Flag User", :url => flag_user_path(user.id), :method => :get, :remote => true %>
    

    to:

    <%= link_to "Flag User", flag_user_path(user.id), :method => :get, :remote => true %>
    

    and everything works was expected. I was incorrectly using it like link_to_remote which requires the :url symbol. Thanks everyone for their input.

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

Sidebar

Related Questions

I'm very new to Ruby on Rails and learning while trying to fix some
I am very new to Ruby on Rails and I'm trying to access the
I'm very new to Ruby on Rails so please go easy! I've uploaded the
I have built a very simple blog application using Ruby on Rails. New to
I'm very new to ruby. I'm trying to search for any instance of a
I'm first timer to Ruby on Rails, trying to set it up on RHEL
running: ruby 1.9.3p0 with Rails 3.2.1 Trying to use rspec but when I try
I am very new to ruby on rails. I've installed a complicated ruby on
i am very new to Ruby on rails . while running script/console , i
I'm very new to ruby and I'm trying to write a web application using

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.