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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:53:47+00:00 2026-06-04T07:53:47+00:00

I’m hoping this problem is a fairly simple one as I am relatively new

  • 0

I’m hoping this problem is a fairly simple one as I am relatively new to rails development.
I am trying to make a get request from a controller with a specified action and pass required parameters. This is the relevant code in the helper class:

module ChartsHelper
  def chart_tag (action, height, params = {})
    params[:format] ||= :json
    path = charts_path(action, params)
    content_tag(:div, :'data-chart' => path, :style => "height: #{height}px;") do
      image_tag('loading.gif', :size => '32x32', :class => 'spinner')
  end
 end
end

and the corresponding action in the ChartsController:

class ChartsController < ApplicationController

  def week_events_bar_chart
    days = (params[:days] || 30).to_i
    render :json => {
      :type => 'AreaChart',
      :cols => [['string', 'Date'], ['number', 'subscriptions']],
      :rows => (1..days).to_a.inject([]) do |memo, i|
        date = i.days.ago.to_date
        t0, t1 = date.beginning_of_day, date.end_of_day
        subscriptions = Kpsevent.all.count
        memo << [date, subscriptions]
        memo
      end.reverse,
      :options => {
        :chartArea => { :width => '90%', :height => '75%' },
        :hAxis => { :showTextEvery => 30 },
        :legend => 'bottom',
      }
    }
  end
end

The routes file has the following:

resource :charts do
    get 'week_events_bar_chart'
end

However I get the following output when trying to perform this request:

 Started GET "/charts.week_events_bar_chart?days=14" for 127.0.0.1 at Tue May 22 00:31:48 +1200 2012
   Processing by ChartsController#index as 
   Parameters: {"days"=>"14"}

And the controller action is never called.
Is anyone able to help with this problem?

EDIT: rake routes output:

week_events_bar_chart_charts GET    /charts/week_events_bar_chart(.:format) {:controller=>"charts", :action=>"week_events_bar_chart"}
POST   /charts(.:format)                  {:controller=>"charts", :action=>"create"}
new_charts GET    /charts/new(.:format)    {:controller=>"charts", :action=>"new"}
edit_charts GET    /charts/edit(.:format)  {:controller=>"charts", :action=>"edit"}
GET    /charts(.:format)                   {:controller=>"charts", :action=>"show"}
PUT    /charts(.:format)                   {:controller=>"charts", :action=>"update"}
DELETE /charts(.:format)                   {:controller=>"charts", :action=>"destroy"}
  • 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-04T07:53:48+00:00Added an answer on June 4, 2026 at 7:53 am

    To your comment on console:

    in rails chart_path(x,...) will generate a route to ChartsController#show with param id = x, which is by default GET /charts/x. By naming your parameter ‘action’, you fooled yourself, ‘week_events_bar_chart’ will just be the id in the restful route.

    To your original code:
    charts_path(x, params) will route to ChartsController#index with format x, which looks like GET /charts.week_events_bar_chart, again calling it action fooled you.

    What you need is the named route helper week_events_bar_chart_charts_path for your action.

    But since you seem to want your helper action dependent, i recommend url_for.
    http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-url_for

    module ChartsHelper
      def chart_tag(action, height, params = {})
        params[:format] ||= :json
        url = url_for({:action => action, :controller => 'charts'}.merge(params))
        content_tag(:div, :'data-chart' => url, :style => "height: #{height}px;") do
          image_tag('loading.gif', :size => '32x32', :class => 'spinner')
      end
     end
    

    end

    If you really want full path you pass :only_path => false to url_for.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
this is what i have right now Drawing an RSS feed into the php,
I am reading a book about Javascript and jQuery and using one of the

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.