Wednesday, June 29, 2016

How can I repeat a POST request in Rails? | Fixed issues

How can I repeat a POST request in Rails? | Fixed issues


How can I repeat a POST request in Rails?

Posted: 29 Jun 2016 08:23 AM PDT

I have some error-handling code that sometimes needs to do some stuff and then re-try the current request. This works fine when it's a GET request, but not otherwise. In other words, I can't redirect_to request.path when request.post? is true.

Is there some way I can take the current request object, be it GET, POST, PATCH, or whatever, and just restart it?

Accessing value of select_tag in Controller

Posted: 29 Jun 2016 08:16 AM PDT

I am having trouble accessing a value of select_tag in my controller. I have the following select_tag in my view:

= select_tag "yessir", options_for_select([ ["No Teardown Time","0"],["15 Minutes", "15"], ["30 Minutes", "30"], ["45 Minutes", "45"], ["60 Minutes", "60"], ["75 Minutes", "75"], ["90 Minutes","90"], ["105 Minutes", "105"],["120 Minutes","120"]], @event.teardown_time), {:prompt => 'Teardown Time'}  

And I try to access it in my controller like such:

a = params["yessir"]  

I have also tried

a = params[:yessir]  

But in either case I keep on getting undefined local variable or method `params' for #. Any suggestions? Cheers~

Capistrano 3 does not restart my rails app after deployment

Posted: 29 Jun 2016 08:14 AM PDT

I use the following deploy.rb :

# config valid only for current version of Capistrano  lock '3.4.0'  set :application, '*****'  set :rails_env, 'production'  set :repo_url, 'admin@test.*******.***:/srv/outils/repos/*****'  set :scm, :git    namespace :deploy do      after :restart, :clear_cache do      on roles(:web), in: :groups, limit: 3, wait: 10 do        # Here we can do anything such as:        # within release_path do        #   execute :rake, 'cache:clear'        # end      end    end    #after 'deploy:publishing', 'deploy:restart'  end  after 'deploy:publishing', 'deploy:restart'  

It correctly deploy the app but does not restart it. What should i modify to make it restart? There is no message, error or otherwise, about the restart.

Creating rails cookie when force_ssl

Posted: 29 Jun 2016 08:14 AM PDT

There Rails project. It works on https (config.force_ssl = true) and is located on the subdomain.

Cookie I need on the primary domain and all its sub-domains, ssl only on where is created cookie.

So I create a cookie:

cookies.permanent[:my_uid] = {value: @ user.id, domain:: all, secure: false}  

And here is what my browser this cookie:

enter image description here

Due force_ssl: true ignored cookie flag secure: false. How to avoid it?

Rails instance object valivate

Posted: 29 Jun 2016 08:26 AM PDT

I was trying to practice Rspec, but seems I was confused about some rails part.

Here is Zombie.rb

class Zombie < ActiveRecord::Base      validates :name, presence: true      has_many :tweets      def hungry?          true      end  end  

It seems when I create a Zombie instance, it will check the name attribute. So, I wrote these Rspec code.

it 'should not be hungry after eating' do           @zombie = Zombie.create           @zombie.should_not be_valid          @zombie.hungry?.should be_truthy      end  

Why it will pass? If the @zombie is not valid, why @zombie.hungry? will still return true

MultiJson Oj as a default instead of json_pure in Rails 4?

Posted: 29 Jun 2016 08:08 AM PDT

Is there a way to force Rails 4.2.5 to use MultiJson with Oj by default?

I have it in Gemfile and running MultiJson.engine in the console shows MultiJson::Adapters::Oj.

But on one page I'm getting following error related to encoding and it is using json_pure instead of MultiJson:

/gems/ruby-2.3.1@report/gems/json_pure-1.8.3/lib/json/common.rb:223:in 'encode'

Rails partial for collection, only display certain things for first element

Posted: 29 Jun 2016 08:07 AM PDT

I have a collection of elements I'm rendering in a partial, but I only want to display a certain element with the very first element. My specific instance is displaying email addresses but I only want the email icon to show once next to the first instance (similar to how the Android Contacts app does).

I have a very "hacky" solution that uses instance variables in the view, which is not a good practice. But I'm struggling to find a cleaner way to implement what I want.

The controller:

@email_addresses = EmailAddress.order(:primary) # primary is a boolean value  

The partial:

# views/email_addresses/_email_address.html.erb  <div class="email-address">    <% unless @email_icon_displayed      <% @email_icon_displayed = true %>      <div class="email-address-icon">        <span class="icon email"></span>      </div>    <% end %>    <div class="email-address-value">      <%= email_address.value %>    </div>  </div>  

Calling partial in view:

<%= render partial: "email_addresses/email_address", collection: @email_addresses %>  

This works properly and only displays the email icon for the first element, but instance variables in the view seems like a bad idea.

I am getting following error while running diaspora pod (ruby application) deployed on ubuntu14.04 system

Posted: 29 Jun 2016 08:06 AM PDT

I am getting following error while running diaspora pod (ruby application) deployed on ubuntu14.04 system

bundler: failed to load command: unicorn (/home/ubuntu/.rvm/gems/ruby-2.1.8@diaspora/bin/unicorn)

Require an OS package in capistrano

Posted: 29 Jun 2016 08:13 AM PDT

I need to verify that an OS package is installed after deploying using capistrano (it's a rails project, in case it matters). I'd like to support the major linux distros and OS X. Fortunately, the name of the package is the same on all platforms.

I've thought adding a capistrano task, something like (untested code):

%w(yum apt-get brew).each do |manager|    path = `which #{manager}`.chomp    if path && path.size > 0      `#{path} install -y #{PKG}`      return    end  end  

Inspired by this question.

Is there a better way? I've thought checking uname, but it doesn't always have the distro, just "Linux". I also thought using lsb_release or listing files in /etc/*-release, but not all distros support it (e.g. centos).

Model evaluates to nil if declared within 'if' block

Posted: 29 Jun 2016 08:12 AM PDT

I have a rails app that has a model chart, and a chart has a datasource. A datasource may have many datapoints. In my chart create method I have the following line:

@chart = Chart.new(chart_params)  @chart.datasource = Datasource.find_by_id(2)  @chart.save  

This works fine - although it's not what I'm trying to do. What I'm trying to do is the following:

if @chart.id == 2        @chart.datasource = Datasource.find_by_id(2)        @chart.save  end  

When I do that, however, I get NoMethodError in Charts#show

undefined method 'datapoints' for nil:NilClass

The error in my Charts#show is generated starting with:

<% @chart.datasource.datapoints.each do |c| %>            dates.push( "<%= c.date %>" )            counts.push( <%= c.count %> )  <% end %>  

Remember, this works perfectly fine if I hard-code the datasource id outside of an if block, wondering what could be causing this.

Could not find compatible versions for gem "spree_core"

Posted: 29 Jun 2016 07:45 AM PDT

I've just ran through the 'Getting Started' guide from Spree commerce and I've hit an error while following it.

I've run the following commands:

gem install spree_cmd  bundle install  

Then I get hit with the following errors in the console

Bundler could not find compatible versions for gem "spree_core":    In Gemfile:      spree_auth_devise (~> 3.0.0) was resolved to 3.0.5, which depends on        spree_core (~> 3.0.0)        spree (~> 3.1.0) was resolved to 3.1.0, which depends on        spree_backend (= 3.1.0) was resolved to 3.1.0, which depends on          spree_core (= 3.1.0)        spree (~> 3.1.0) was resolved to 3.1.0, which depends on        spree_backend (= 3.1.0) was resolved to 3.1.0, which depends on          spree_core (= 3.1.0)        spree (~> 3.1.0) was resolved to 3.1.0, which depends on        spree_backend (= 3.1.0) was resolved to 3.1.0, which depends on          spree_core (= 3.1.0)        spree (~> 3.1.0) was resolved to 3.1.0, which depends on        spree_backend (= 3.1.0) was resolved to 3.1.0, which depends on          spree_core (= 3.1.0)        spree (~> 3.1.0) was resolved to 3.1.0, which depends on        spree_backend (= 3.1.0) was resolved to 3.1.0, which depends on          spree_core (= 3.1.0)  

Which looks like it all checks out - but it seems to be failing to bundle install.

My Gemfile

gem 'spree', '~> 3.1.0'  gem 'spree_gateway', '~> 3.0.0'  gem 'spree_auth_devise', '~> 3.0.0'  

Any help would be brilliant

Create model based on another model attributes Rails

Posted: 29 Jun 2016 07:44 AM PDT

Lets say i have 2 models Quote and Invoice and they share common fields. How do you convert a Quote to an Invoice. How would that work around the models and controllers with creating a new Invoice based on the values already stored in the Invoice?

Devise sign_in resource works even without importing module

Posted: 29 Jun 2016 07:39 AM PDT

So, I was customizing devise in a custom sign up page which required me to sign_in a user after creating the account along with some other operations. After creating the resource I did

sign_in resource if resource.active_for_authentication?  

and it signs in the user. My controller inherits the ApplicationController and I haven't included any modules like this

include Devise::Controllers::SignInOut  

How did rails know about the

sign_in  

method

Conflicting View Logic

Posted: 29 Jun 2016 07:56 AM PDT

I have a show page where I need to both show the student's units and create a unit for them. However an error is being incurred when trying to do both.

In my controller

def show    @student = Student.find(params[:id])    @unit = @student.units.build    @units = @student.units  end  

In my view

<%= simple_form_for @unit, url: student_units_path(@student) %>    # form...  <% end %>    <% @units.each do |unit| %>    <tr>      <td><%= unit.course %></td>      <td><%= unit.mailing_date.strftime('%m/%d/%y') %></td>    </tr>  <% end %>  

The unit.course call works and any call that is only the first child of unit, however when I call a second method on unit I get this error:

undefined method `strftime' for nil:NilClass  

despite knowing that the unit exists, hence the first call working

How can I proprerly use an instance variable in a link_to?

Posted: 29 Jun 2016 07:34 AM PDT

How can I resolve this ?

I had 2 buttons : /views/subjects/_inscription_button.html.haml

  - if subject.participation(current_participant).nil?      = link_to "Ca m'intéresse !",   subject_participant_index_path(:interested_id => current_participant.id, :subject_id => subject.id), remote: true, :method => :post, class:"btn btn-primary"      - else      = link_to "Ca ne m'intéresse plus !",   delete_participation_path(@subject.participation(current_participant).id),:method => :delete, remote: true, class:"btn btn-primary"  

The second link_to doesn't want to switch properly. I get the error :

NoMethodError at /subject_participant/115 undefined method `id' for nil:NilClass

The instance variable subject works for the first button but not the second...

Here is the rest of the usefull code : subject_participant_controller.rb :

class SubjectParticipantController < ApplicationController    before_action :authenticate_participant!        def create     @subject = Subject.find(params[:subject_id])     @subject_participant = SubjectParticipant.new(subject_participant_params)       if @subject_participant.save       respond_to do | format |        format.html {redirect_to subjects_path}        format.js       end     else      redirect_to subjects_path     end    end      def destroy      @subject_participant = SubjectParticipant.find(params[:id])      if @subject_participant.destroy       respond_to do | format |        format.html {redirect_to subjects_path}        format.js       end      else       redirect_to subjects_path      end    end      def subject_participant_params      params.permit(:interested_id, :subject_id, :id)    end  end  

/routes.rb :

Rails.application.routes.draw do   devise_for :participants   resources :subjects   resources :participants   resources :conferences   resources :subject_participant     delete 'subject_participant/:id' => 'subject_participant#destroy', as: 'delete_participation'   root 'welcome#index'  

subject.rb

class Subject < ActiveRecord::Base    validates_presence_of  :title, :questioner, :conference, :description      has_many :subject_participants    has_many :interested, through: :subject_participants #interested    belongs_to :questioner, class_name: "Participant"    belongs_to :conference      def participation(current_participant)      self.subject_participants.find_by_interested_id(current_participant.id)   end  end  

pg_search seems to ignore `using` for associated_against

Posted: 29 Jun 2016 07:37 AM PDT

I am trying to figure out why the using specifications does not works for the associated against fields. My code is:

 include PgSearch     pg_search_scope :search,      {        :associated_against => {         :client => [:name, :email],       },       :against => [:description],       using: {         tsearch: {},         trigram:    {threshold:  0.1}       }      }  

For field description it works well.

Any tips here ?

Thanks in advance.

How to setup a Ruby On Rails project in IntelliJ 2016? [on hold]

Posted: 29 Jun 2016 07:18 AM PDT

So i am just about to start learning web development by using the ruby on rails framework. I have installed the plugin for Ruby in the intelliJ plugin repository. How do i setup a rails project in IntelliJ 2016?

Rails cache Permission Denied when cache is very large

Posted: 29 Jun 2016 07:08 AM PDT

My app uses extensive rails caching, and all the cache keys are created and used by the same application, which has full rights to the cache folder.

However, occasionally when the cache gets particularly large (large uptick in use within the cache expiration window), I start getting permissions errors when accessing the cache fragments using Rails.cache.fetch:

Permission denied @ unlink_internal  

Clearing the cache "fixes" the problem, until it gets large again. Is there a theoretical limit to the size such a cache can be, or could there be some other cause?

Rails Active Record Omitting Where Clause

Posted: 29 Jun 2016 08:19 AM PDT

I have an Active Record query that sits inside of a gem. Database used is postgres.

Client.where(date:@date,client:@business_id)  

The gem uses a get request to pull this data. When there are too many values in @business_id, the URI is too long. Gem does not have post requests.

Workaround:

The business problem is when all the @business_id get passed to the app. I could have an "all" button, that triggers all the client values to show. I would need to ignore the client:@business_id part of the query.

How could I construct the query so that when all of the @business_id need to be passed, it ignores the client:@business_id part of the query?

Rails, Carrierwave, specifically :image parameter is not even being passed through POST

Posted: 29 Jun 2016 07:14 AM PDT

I am trying to save an :image to an article.

But my form sends ALL the other parameters but not the :image one.

My log:

Started POST "/articles/create" for 127.0.0.1 at 2016-06-29 16:56:59 +0300  Processing by ArticlesController#create as HTML    Parameters: {"utf8"=>"✓", "authenticity_token"=>"Neo/3LqX40cQKzlCwrK8cxYdkb6g95d1dbihCRtL5J8uIPZ5M7OOCbe+IWU9mwWK7dmqJy6s3G7uDXuvI2ZxiQ==", "article_type"=>"news", "article"=>{"strings"=>{"1"=>{"title"=>"sds", "text"=>"dsds"}}}}  

My form:

<%=form_for @article, url: articles_create_path, remote: true, authenticity_token: true, html: {class: "form-horizontal"} do |f|%>          <%= hidden_field_tag 'article_type', @articleType  %>          <fieldset class="content-group">          <%if !(@articleType=='notifs') %>            <legend class="text-bold">Image</legend>              <div class="form-group">              <div class="col-lg-10">                <%= f.file_field :image, :class => 'file-input-custom', 'data-show-caption' => true, 'data-show-upload' => false, :accept => 'image/*'%>              </div>            </div>            <% end %>          </fieldset>          <%= f.fields_for :strings do |fa| %>          <fieldset class="content-group">            <legend class="text-bold">Localization</legend>            <div class="tabbable">                <div class="tab-content">                <% @languages.each do |lang| %>                <%= fa.fields_for lang.id.to_s do |fb| %>                  <div class="tab-pane active" id="basic-justified-tab-<%= lang.id %>">                  <div class="form-group">                    <label class="col-lg-2 control-label text-semibold"><%= lang.name %> Title: <span class="text-danger">*</span></label>                    <div class="col-lg-10">                      <%= fb.text_field :title, :class => 'form-control', :required => 'required' %>                    </div>                  </div>                    <div class="form-group">                    <label for="title" class="col-md-4 col-md-offset-1"><%= lang.name %> Text:</label>                    <%= fb.text_area :text, :style => "height: 150px;", :class => 'wysihtml5 wysihtml5-min form-control', :required => 'required' %>                  </div>                </div>                <hr>                  <% end %>                <% end %>              </div>            </div>            </fieldset>          <% end %>                                          <div class="form-group">              <div class="col-md-2 col-md-offset-8">              <input type="submit" class="btn btn-success" value="Submit" >            </div>            </div>            <% end %>  

And my Articles controller:

class ArticlesController < ApplicationController      before_action :set_article, only: [:edit, :delete, :update, :destroy]        def new          @articleType = params[:article_type]          @article = Article.new          @languages = Language.all      end        def create            @article = Article.new(article_params)          @article.article_type = params[:article_type]            if @article.save && manage_strings              @status = 'success'          else              @status = 'error'              @errormessages = @article.errors.full_messages          end          respond_to do |format|              format.js          end      end        def edit                end        def update          @articleType = @article.article_type          if @article.update(article_params) && manage_strings              @status = 'success'          else              @status = 'error'              @errormessages = @article.errors.full_messages          end          byebug          respond_to do |format|                format.js          end      end        def delete_article          @article = Article.find(params[:id])          @articleType = @article.article_type          if @article.destroy              @status = 'success'          else              @status = 'error'              @errormessages = @article.errors.full_messages          end          respond_to do |format|              format.js          end      end        private            def article_params                if params[:article][:image].present?                  params.require(:article).permit(:id, )              else                  params.require(:article).permit(:id,:image)              end          end        def set_article          @article = Article.find_by_id(params[:id])            @languages = Language.all      end            def manage_strings          if params[:article][:strings].any?              params[:article][:strings].each do |key,value|                  string = @article.localizations.find_or_initialize_by(:language_id => key.to_i)                  string.title = params[:article][:strings][key][:title]                  string.text = params[:article][:strings][key][:text]                  string.save              end          end       end    end  

I have a string :image in my articles table and I do have

mount_uploader :image, ImageUploader

In my Articles

Can you find what am I doing wrong? Could it be something wrong with Carrierwave and should I try to use another similar gem?

Seed Database with Data for Each User

Posted: 29 Jun 2016 07:06 AM PDT

I am trying to figure out the best way to populate the database for each user. My end target is to have each user who has_many goals have a list of prepopulated goals when the user is created. The issue I see with seeding is that this will only create ONE set of goals for every user to "share" and not an individual set of goals for each user with the same initial data.

This is my current layout:

weekly_goals table

user_id  title  status  

User.rb

has_many :weekly_goals  

WeeklyGoal.rb

belongs_to :user    #List of all goals hardcoded in  

Am I going about this with the wrong thought process? Is there a better way to do what I'm asking? Thanks!

Ruby Workflow Issue During Migration

Posted: 29 Jun 2016 07:00 AM PDT

I am using Ruby Workflow in my ActiveRecords using Gem: Workflow

Existing Running Code contains:

  • I am having an ActiveRecord: X
  • I am having two Migrations already:
    • (Ref1) CreateX migration (which creates table X)
    • (Ref2) CreateInitialEntryInX migration (which creates one entry in table X)

New Changes:

  • Now I wanted to add workflow in ActiveRecord X, hence I did:
    • (Ref3) I added the workflow code in ActiveRecord Model X (mentioning :status as my workflow field)
    • (Ref4) AddStatusFieldToX migration (which adds :status field in table X)

Now when I run rake db:migrate after the changes, the (Ref2) breaks cos Migration looks for :status field as it is mentioned in ActiveRecord Model in the Workflow section, but :status field has not been added yet as migration (Ref4) has not executed yet.

Hence, all the builds fail when all migrations are run in sequence, Any solution to this? I do not want to resequence any of the migration or edit any old existing migrations.

Unable to autoload constant ProfileProjectsController

Posted: 29 Jun 2016 06:42 AM PDT

I am getting an error while visiting /project/my/tasks in Rails 5 as Unable to autoload constant ProfileProjectsController, expected /home/ubuntu/workspace/app/controllers/profile_projects_controller.rb to define it

controller code

class Project::ProfileProjectsController < ApplicationController    def index      if current_user        @projects = Project.where(user_id: current_user.id)        render 'profile_projects/index'      end    end  end  

Multiple rails forms on same page: clicking submit button per form always works in safari, sometimes works in firefox

Posted: 29 Jun 2016 08:06 AM PDT

On an index page I have a table with a bunch of listed items. Each <tr></tr> within the table's <tbody>not only lists each item, but also allows you to

  • update that item
  • click edit to take you to the edit screen for that item

Here is a picture:

Showing table

Within development in safari: I can successfully update each listed item and it all works just fine. However: when running my feature spec with capybara and selenium-webkit (which uses firefox):

  • It appears that capybara finds the submit button ok and even clicks it
  • But then nothing happens. For some reason the form appears to not be submitting when that update button is clicked.

To make things even more strange: in development mode while testing with firefox, clicking the update button works sometimes. Sometimes it doesn't work and I have to refresh the page, and then it works.

I tried putting a binding.pry in right before clicking the Update abc button in order to manually click the button at that step. I noticed that clicking the button manually was not submitting the form either.

Here is my relevant spec:

scenario "within the index page", js: true do    select 'some selection', from 'item_1_jazz'    select '12345', from 'item_1_something'    # I attempted putting a binding.pry here, and noticed that clicking the update button still wasn't submitting the form    find("#update_some_item_1_btn").click      expect(page).to have_content 'The item was successfully updated.'  end  

Update Here are my buttons within the form:

<td class="btn-group">    <%= f.submit 'Update abc', class: "btn btn-success btn-sm", id: "update_#{dom_id(item)}_btn" %>    <%= link_to edit_item_path(item), class: "btn btn-info btn-sm" do %>      <i class="fa fa-pencil"></i> Edit    <% end %>  </td>  

Question: In firefox: Capybara appears to find the submit button just fine and even click it. But why isn't Capybara able to submit the form within Firefox? Also: why in development mode with firefox does the button only work sometimes? It appears something is stopping the form form from submitting.

How to install and configure geckodriver on Rails / Ubuntu

Posted: 29 Jun 2016 06:09 AM PDT

I'm using Watir to scrape in production, but due to some firefox issues, it no longer is able to launch a browser (see here Watir Webdriver(0.9.1) No Longer Opens an Instance of Firefox).

Gecko driver is here: https://github.com/mozilla/geckodriver

How do I install geckodriver and configure rails to use it instead of the default firefox binary?

Thanks for any help.

Google Places gem error

Posted: 29 Jun 2016 06:13 AM PDT

I am trying to use the next page token from the first page results that are retrieved by the call to the Google Places, using the following code:

   def pins_in_area              @client = GooglePlaces::Client.new('api_key_XXXXX')              @results = @client.spots(params[:lat], params[:long], :radius => params[:radius])              puts @results              next_page_token = @results.last.nextpagetoken              puts next_page_token #spots_by_pagetoken              next_spots = @client.spots_by_pagetoken(next_page_token)              puts next_spots  

... end

But, I encounter the following error, not sure why:

Completed 500 Internal Server Error in 258ms (ActiveRecord: 0.0ms)    GooglePlaces::InvalidRequestError (GooglePlaces::InvalidRequestError):    app/controllers/api/v1/pins_controller.rb:89:in `pins_in_area'        Rendered /usr/local/rvm/gems/ruby-2.2.1/gems/actionpack-4.2.4/lib/action_dispatch/middleware/templates/rescues/_source.erb (13.1ms)    Rendered /usr/local/rvm/gems/ruby-2.2.1/gems/actionpack-4.2.4/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (35.1ms)    Rendered /usr/local/rvm/gems/ruby-2.2.1/gems/actionpack-4.2.4/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (2.0ms)    Rendered /usr/local/rvm/gems/ruby-2.2.1/gems/actionpack-4.2.4/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb within rescues/layout (101.1ms)  

l18n keep locale variable changing link rails

Posted: 29 Jun 2016 06:31 AM PDT

I am developing a rails application which must be in English or in Hungarian. The user may choose the language. So I use Rails Internationalization (I18n) API. The problem is that I do not understand how to keep the variable 'locale' when the user changes page.

#application_controller.rb  before_action :set_locale  def set_locale      I18n.locale = params[:locale] || I18n.default_locale  end  

Thanks a lot for your answers

foreman stop mina create current folder

Posted: 29 Jun 2016 06:09 AM PDT

Does someone know why the mina can't create the current directory after add foreman?

-----> Cleaning up old releases (keeping 5)
-----> Exporting foreman procfile for bash: line 152: cd: /home/ubuntu/test/current: File or directory not found sudo: bundle:
command not found ! ERROR: Deploy failed.
-----> Cleaning up build Unlinking current OK Connection to 55.77.221.43 closed.

deploy do      # Put things that will set up an empty directory into a fully set-up      # instance of your project.      invoke :'git:clone'      invoke :'deploy:link_shared_paths'      invoke :'bundle:install'      invoke :'rails:db_migrate'      invoke :'rails:assets_precompile'      invoke :'deploy:cleanup'      invoke :'foreman:export'          to :launch do        queue "mkdir -p #{deploy_to}/#{current_path}/tmp/"        queue "touch #{deploy_to}/#{current_path}/tmp/restart.txt"        invoke 'foreman:restart'      end  

How to convert human readable number to actual number in Ruby?

Posted: 29 Jun 2016 07:10 AM PDT

Is there a simple Rails/Ruby helper function to help you convert human readable numbers to actual numbers?

Such as:

1K => 1000    2M => 2,000,000    2.2K => 2200    1,500 => 1500    50 => 50    5.5M => 5500000  

how to draw pie chart in rails?

Posted: 29 Jun 2016 05:59 AM PDT

I have to models. Employee and locations . the association between them is location has many employees. and employee belongs to location. i want to draw a pie chart between this 2 models. means i want to show all locations and employees count of that location in pie chart. how can i do that?

i was trying to implement this using the Chartkick gem.

but do not know how to draw the graph between them.

No comments:

Post a Comment