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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T18:48:04+00:00 2026-05-15T18:48:04+00:00

I’m doing my best to create a site badge or widget for my site

  • 0

I’m doing my best to create a site badge or widget for my site, which is a rails site.

Essentially it’s a site where users post content that they’ve created and other who like that content can make a donation to express their appreciation for it.

I asked a similar question a while back about how to create a widget, but that was before I had done any real study of Javascript.

The first script (in localhost:3000/javascripts/widget.js) worked fine I think:

    var Widget = 
{
    init:function()
    {
        var loc = window.location;
        var title = document.title;
        var href = 'http://localhost:3000/donations/new.js?url=' + encodeURIComponent(loc);

        href = href + '&title=' + encodeURIComponent(title);

        var script = document.createElement('script');
        script.src = href;
        script.type = "text/javascript";

        document.documentElement.firstChild.appendChild(script);

    }
};
Widget.init();

(The reason why I entitled it new.js was because that’s where all the statistics for the link are displayed on the main site)
To test this script I made a simple HTML file to call it:

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>Test Widget</title>
        <script src="http://localhost:3000/javascripts/widget.js" type="text/javascript"></script>
    </head>
    <body>
        <h1>Test Widget</h1>
    </body>
</html>

When the above script runs I checked firebug and sure enough it calls the second script:

<script src="http://localhost:3000/donations/new.js?url=file%3A%2F%2F%2FC%3A%2Fgoldhat_production%2Ftest_widget.html&amp;title=Test%20Widget" type="text/javascript"></script>

Finally I created a new.js.erb file with the following script just to make sure that it was being called:

var Stats =
{
    init: function()
    {
        alert("Hello World!");
    }
};
Stats.init();

And in the donations controller I added the following code to the “new” action:

respond_to do |format|
    format.js
    format.html
end 

So I gave it a whirl and I don’t get a Hello World alert when I refresh the page but when I get what is actually being called I get this error (truncated):

 26<h1>
27 ActionController::MethodNotAllowed
28
29</h1>
30<pre>Only put requests are allowed.</pre>
31
32
33
34<p><code>RAILS_ROOT: c:/goldhat_production</code></p>
35
36<div id="traces"> 

There seems to be a lot of places where I could go wrong with this, I’m not sure where, though.

  • 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-15T18:48:04+00:00Added an answer on May 15, 2026 at 6:48 pm

    Your routes.rb file is only allowing put requests to your new action. New should allow get if you are using map.resources, but it appears you are not using that functionality.

    I see you have three options:

    1) If you are going to be using rjs, then move the javascript call to a different method that isn’t already being used and set up the route to that action if necessary.

    map.connect '/donations/[action_name]', :controller => 'donations', :action => '[action_name]', :conditions => { :method => :get }
    

    2) If you are not going to be using rjs, just move it to static resources. Just move the file to your /public/javascripts directory and link to it from there.

    3) allow get requests to your new method, by adding this to your routes.rb. This might be just allowing the action in your existing route statement, depending on what is already there.

    map.connect '/donations/new', :controller => :donations, :action => :new, :conditions => { :method => :get }
    

    I would personally go with option 1 or 2, just because I don’t see the relationship to “new”, but I likely don’t see the full picture.

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

Sidebar

Related Questions

I'm trying to create an if statement in PHP that prevents a single post
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I used javascript for loading a picture on my website depending on which small
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I

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.