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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T21:57:47+00:00 2026-05-19T21:57:47+00:00

None of the tutorials I seem do what I’m trying to do. Very simply,

  • 0

None of the tutorials I seem do what I’m trying to do. Very simply, I want a user to be able to submit a POST request to a controller (to “LIKE” a video) and have the controller respond back with a JSON object. Any help would be appreciated.

Thanks

EDIT Because SO is messing the formatting up, here is a gist of my code too:
https://gist.github.com/813503

Here is my controller:

class LikesController < ApplicationController

  before_filter :get_ids

  respond_to :json, :js

  def videolink
    results = {}

    # check to see if the user has liked this videolink before
    if current_user
      liked = Like.video?(current_user, @vid_id)

      results["status"] = "OK"      
      results["liked"] = liked
    else
      results["status"] = "Error"
      results["message"] = "User not logged in"
    end

    respond_with( results.to_json ) 
  end


  def update
    results = {}

    if current_user
      results["status"] = "OK"  
    else
      results["status"] = "Error"
      results["message"] = "User not logged in"
    end

    respond_with( results.to_json )
  end


  private

  def get_ids
    @vid_id = params[:videolink_id]
  end

end

Here is my JS file:

$("#likeVideo").click(function() {
    $.ajax({
        contentType: "application/json",
        data: { game_id: game_id,   videolink_id: current_video["videolink"]["id"] },
        dataType: "json",
        type: "POST",
        url: "/likes/" + game_id,
        success: function(data) {
            console.log("Success", data);
        }
    });     

    return false;
});

My routes:

  resources :likes do
    collection do
      get "videolink"
    end

    member do
      post :update
    end
  end

And here is the error I get:

NoMethodError
in LikesController#update

undefined method `{"status":"OK"}_url' for #<LikesController:0x0000010178be58>

  • 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-19T21:57:47+00:00Added an answer on May 19, 2026 at 9:57 pm

    If you want to send back custom JSON, Instead of respond_with(results.to_json)… just render the text

    render :text=>results.to_json
    

    The responds_with is a way for you to easily send back objects, with their location (url). So that’s why your error is telling you that that ‘_url’ is invalid.

    More info on responds_with, courtesy of http://ryandaigle.com/articles/2009/8/10/what-s-new-in-edge-rails-default-restful-rendering

    If another format was requested, (i.e.
    :xml or :json)

    • If it was a GET request, invoke the :to_format method on the resource and
      send that back
    • If the resource has validation errors, send back the errors in the
      requested format with the
      :unprocessable_entity status code
    • If it was a POST request, invoke the :to_format method on the resource
      and send that back with the :created
      status and the :location of the new
      created resource
    • Else, send back the :ok response with no body
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've found a bunch of map_reduce tutorials around, but none of them seem to
I've been through a few of the tutorials, but none of them seem to
hey, i know there's lots of tutorials out there but none seem to be
Lots of tutorials around the net but none of them can explain me this:
I've read a lot of examples and tutorials about it. But none of the
Since it seems none exist, I'm trying to make a chrome extension to set
I am trying to display(block,none) select boxes(in this example only one select box) through
I want to know if all (or none) of the items of a Collection
I've been trying to figure this out for a day and none of the
I've read several tutorials for adding custom styles to the WYSIWYG (TinyMCE) editor. None

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.