Monday, January 2, 2017

Ho to write a scope to display ratings for an Event - Rails 5 | Fixed issues

Ho to write a scope to display ratings for an Event - Rails 5 | Fixed issues


Ho to write a scope to display ratings for an Event - Rails 5

Posted: 02 Jan 2017 07:53 AM PST

  • I would like to write a scope that lists all the ratings for an event.
  • can one advise me how to write a scope that list the ratings for the event = Event.find(5) which is represented as :rateable_id => 5

Terminal:

2.3.0 :005 >   event = Event.find(5)    Event Load (0.2ms)  SELECT  "events".* FROM "events" WHERE "events"."id" = ? LIMIT ?  [["id", 5], ["LIMIT", 1]]   => #<Event id: 5, title: "Speed Social - Graduate Professionals", description: "Lorem ipsum dolor sit amet, consectetur adipiscing...", created_at: "2016-12-04 14:02:09", updated_at: "2016-12-04 14:02:09", slug: nil>   2.3.0 :006 >   2.3.0 :007 >     2.3.0 :008 >   ap Rate.all    Rate Load (0.3ms)  SELECT "rates".* FROM "rates"  [      [0] #<Rate:0x007f84fd142380> {                     :id => 8,               :rater_id => 1,          :rateable_type => "Event",            :rateable_id => 5,                  :stars => 3.0,              :dimension => "style",             :created_at => Mon, 02 Jan 2017 15:00:51 UTC +00:00,             :updated_at => Mon, 02 Jan 2017 15:00:51 UTC +00:00      },      [1] #<Rate:0x007f84fd142178> {                     :id => 9,               :rater_id => 4,          :rateable_type => "Event",            :rateable_id => 5,                  :stars => 2.0,              :dimension => "style",             :created_at => Mon, 02 Jan 2017 15:12:29 UTC +00:00,             :updated_at => Mon, 02 Jan 2017 15:12:29 UTC +00:00      },      [2] #<Rate:0x007f84fd141f70> {                     :id => 10,               :rater_id => 1,          :rateable_type => "Event",            :rateable_id => 6,                  :stars => 4.0,              :dimension => "style",             :created_at => Mon, 02 Jan 2017 15:40:37 UTC +00:00,             :updated_at => Mon, 02 Jan 2017 15:40:37 UTC +00:00      }  ]   => nil   

schemas

ActiveRecord::Schema.define(version: 20170102134239) do      create_table "events", force: :cascade do |t|      t.string   "title"      t.text     "description"      t.datetime "created_at",  null: false      t.datetime "updated_at",  null: false      t.string   "slug"      t.index ["slug"], name: "index_events_on_slug", unique: true    end      create_table "events_users", id: false, force: :cascade do |t|      t.integer "event_id", null: false      t.integer "user_id",  null: false    end      create_table "overall_averages", force: :cascade do |t|      t.string   "rateable_type"      t.integer  "rateable_id"      t.float    "overall_avg",   null: false      t.datetime "created_at"      t.datetime "updated_at"    end      create_table "rates", force: :cascade do |t|      t.integer  "rater_id"      t.string   "rateable_type"      t.integer  "rateable_id"      t.float    "stars",         null: false      t.string   "dimension"      t.datetime "created_at"      t.datetime "updated_at"      t.index ["rateable_id", "rateable_type"], name: "index_rates_on_rateable_id_and_rateable_type"      t.index ["rater_id"], name: "index_rates_on_rater_id"    end      create_table "rating_caches", force: :cascade do |t|      t.string   "cacheable_type"      t.integer  "cacheable_id"      t.float    "avg",            null: false      t.integer  "qty",            null: false      t.string   "dimension"      t.datetime "created_at"      t.datetime "updated_at"      t.index ["cacheable_id", "cacheable_type"], name: "index_rating_caches_on_cacheable_id_and_cacheable_type"    end      create_table "users", force: :cascade do |t|      t.string   "email",                  default: "", null: false      t.string   "encrypted_password",     default: "", null: false      t.string   "reset_password_token"      t.datetime "reset_password_sent_at"      t.datetime "remember_created_at"      t.integer  "sign_in_count",          default: 0,  null: false      t.datetime "current_sign_in_at"      t.datetime "last_sign_in_at"      t.string   "current_sign_in_ip"      t.string   "last_sign_in_ip"      t.datetime "created_at",                          null: false      t.datetime "updated_at",                          null: false      t.string   "firstname"      t.string   "lastname"      t.string   "slug"      t.index ["email"], name: "index_users_on_email", unique: true      t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true      t.index ["slug"], name: "index_users_on_slug", unique: true    end    end  

How can I automatically run Bundler within the project directory when Vagrant is provisioning?

Posted: 02 Jan 2017 07:09 AM PST

I'd like to Bundler to install Rails project dependencies when Vagrant is provisioning a new VM. This is what I currently have, but I get this line printed ==> default: Could not locate Gemfile or .bundle/ directory. The project directory does contain a Gemfile.

Vagrantfile

# -*- mode: ruby -*-  # vi: set ft=ruby :    VAGRANTFILE_API_VERSION = "2"    Vagrant.require_version ">= 1.9.1"    Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|      config.vm.box = "bento/ubuntu-16.04"      # Configurate the virtual machine to use 2GB of RAM    config.vm.provider :virtualbox do |vb|      vb.customize ["modifyvm", :id, "--memory", "2048"]      vb.name = "Nuggets_API_Env"    end      # Forward the Rails server default port to the host    config.vm.network :forwarded_port, guest: 3000, host: 3000      # Use Chef Solo to provision our virtual machine    config.vm.provision :chef_solo do |chef|      chef.cookbooks_path = ["cookbooks"]        chef.add_recipe "apt"      chef.add_recipe "build-essential"      chef.add_recipe "nodejs"      chef.add_recipe "openssl"      chef.add_recipe "ruby_build"      chef.add_recipe "ruby_rbenv::user"      chef.add_recipe "vim"      chef.add_recipe "postgresql::config_initdb"      chef.add_recipe "postgresql::server"      chef.add_recipe "postgresql::client"        chef.json = {        postgresql: {          apt_pgdg_postgresql: true,          version: "9.5",          password: {            postgres: "test1234",          }        },        rbenv: {          user_installs: [{            user: 'vagrant',            rubies: ["2.4.0"],            global: "2.4.0",            gems: {              "2.4.0" => [                { name: "bundler" }              ]            }          }]        },      }    end      config.vm.provision "shell" do |s|      s.path = "VM_Local_Setup.sh"      s.upload_path = "/vagrant/VM_Local_Setup.sh"      s.privileged = false    end    end  

Cheffile

site "https://supermarket.getchef.com/api/v1"    cookbook 'apt'  cookbook 'build-essential'  cookbook 'nodejs'  cookbook 'openssl'  cookbook 'postgresql'  cookbook 'ruby_build'  cookbook 'ruby_rbenv'  cookbook 'vim'  

VM_Local_Setup.sh

#!/bin/bash    sudo apt-get update  sudo apt-get upgrade -y  bundler install  rbenv rehash  

Highcharts Tooltip not rendering properly if it has material icons

Posted: 02 Jan 2017 07:39 AM PST

In my rails application I have a graph with icons generated with Highcharts. The icons are Google Material design icons that I get through a material-icons gem. https://github.com/Angelmmiguel/material_icons.

I want to do 2 things with the icons:

  1. Instead of numeric labels I want smileys. This I got working

    yAxis: {          max: 5,          min: 1,          labels: {              formatter: function () {                  if (this.value == 1) {                      return '<i class="material-icons">sentiment_very_dissatisfied</i>'                  }                  if (this.value == 2) {                      return '<i class="materialicons">sentiment_dissatisfied</i>'                  }                  if (this.value == 3) {                      return '<i class="material-icons" height="5px">sentiment_neutral</i>'                  }                  if (this.value == 4) {                      return '<i class="material-icons">sentiment_satisfied</i>'                  }                  if (this.value == 5) {                      return '<i class="material-icons">sentiment_very_satisfied</i>'                  } else {                      return this.value                  }              }          }      },  

    enter image description here

  2. Instead of numeric values in the tooltip I want smileys. This is where it goes wrong.

    tooltip: {          formatter: function () {              var date = Highcharts.dateFormat('%d-%m-%y %H:%M',                  new Date(this.x));              var getIcon = function (y) {                  if (y == 1) {                      return '<i class="material-icons">sentiment_very_dissatisfied</i>'                  }                  if (y == 2) {                      return '<i class="material-icons">sentiment_dissatisfied</i>'                  }                  if (y == 3) {                      return '<i class="material-icons">sentiment_neutral</i>'                  }                  if (y == 4) {                      return '<i class="material-icons">sentiment_satisfied</i>'                  }                  if (y == 5) {                      return '<i class="material-icons">sentiment_very_satisfied</i>'                  } else {                      return y                  }              };              var icon = getIcon(this.y);              console.log(date);              return '<b>' + this.series.name + '</b><br/>' + date + ' : ' + icon;          },  

    I have to parse the date because it is a JavaScript epoch time(milliseconds). Without + icon the date is shown. If I add + icon it doesn't work and the date will not correctly render. What I noticed is that the icon is higher than the line itself. So I think this is a CSS problem, but I don't know how to fix it.
    Without:withoutWith:with

Thanks in advance for replying!

Update Attributes of a Specific Record

Posted: 02 Jan 2017 06:09 AM PST

Let's say I have a bunch of cards listed on my wall show action. When you interact with a card (click it for example), I want to update that card's attributes.

I'm currently doing this by getting the card's attributes with Javascript, adding them to a card form and submitting the form remotely.

I have the card's ID, but how do I tell the form which card I want to update?

What should the form and controller update action look like?

This is what I have so far

Form

<%= form_for(@card, remote: true) do |f| %>      <%= f.text_field :list_id %>      <%= f.text_field :order %>  <% end %>  

Controller

def update      @card = Card.find(params[:id])        if @card.update_attributes(shared_params)          redirect_to edit_card_path(@card, format: :html)      else          render :edit      end  end  

bootstrap star rating and dynamic tabs conflict

Posted: 02 Jan 2017 06:26 AM PST

In my Rails application I am using bootstrap dynamic tabs which was working fine but when I included the js of bootstrap-star-rating from https://github.com/kartik-v/bootstrap-star-rating/blob/master/js/star-rating.js it stopped working.

This is my Rails application.js file

//= require jquery  //= require jquery_ujs  //= require jquery-ui  //= require bootstrap.min  //= require bootstrap-slider  //= require timepicker.min  //= require modernizr.custom  //= require star-rating  //= require page    

And this is the code for showing bootstrap stars in page.js file:

$(document).ready(function () {      $("a[href='#overview']").click(function(){      $(this).parent('li').addClass('active')      $("[data-toggle=tab]").parent('li').removeClass('active')      $(".tab-pane").addClass('active in')    })        $('.star-rating').rating({min: 0,max: 5,step: 1,size: 'xs',showClear: false,showCaption: false});      $('.star-rating').on('rating.change', function() {      rating = $(this).val()      get_id = $(this).attr('id')      $('input#'+get_id+'_rating').val(rating)    });  

And this is the code for bootstrap tabs.

      %ul.nav.nav-tabs          %li.active            %a{"data-toggle" => "tab",:href => "#overview"} Overview          %li            %a{"data-toggle" => "tab", :href => "#offers"} Offers          %li            %a{"data-toggle" => "tab", :href => "#services"} Services          %li            %a{"data-toggle" => "tab", :href => "#reviews"} Reviews        .tab-content          #overview.tab-pane.active.fade.in            %h3.hidden-heading  Overview            %p= @business["description"]         #offers.tab-pane.active.fade.in  

Ruby on rails Failed to precompile

Posted: 02 Jan 2017 06:17 AM PST

I'm learning to make a web-app for a week and I'm successful to run it locally,but can't push it to heroku master. I get the following error:

enter image description here

Link to specific ajax tab in rails

Posted: 02 Jan 2017 07:37 AM PST

I have a question that I have not found a answer for yet.

In my Rails 4 application I use ajax tabs. Here is an example for the code setup.

show.html.erb

<div id="ajaxtabs">    <ul class="nav nav-tabs">      <li><%= link_to 'Members', some_member_path, :remote => true %></li>      <li><%= link_to 'Hosts', some_host_path, :remote => true %></li>    </ul>   </div>  <div class="tab-content">    <div id="tab-display"></div>  </div>  

members.js.erb

$("#tab-display").html("<%= escape_javascript (render partial: 'members') %>");  

_members.html.erb

 "This is the partial displayed when the members tab is clicked"  

Everything work beautifully, but there is one feature that I would like to get to work, and that is the ability to link to a specific tab.

For example if I would like to link to the members tab I could type the url maybe like? sitename.com/groups/#members-tab

unpermitted parameter simple_form

Posted: 02 Jan 2017 06:17 AM PST

I am trying to create a nested form with Simple_fields in ruby 4. However, every time i try to enter data into the form i get a unpermitted parameter error in the serverconsole after trying to submit. I already tried the sollutions found in the simple_form wiki and did some testing, but that doesn't seem to work.

The _form:

<%= simple_form_for(@enquiry) do |f| %>      <%= f.error_notification %>        <div class="form-inputs">        <H1>Algemene informatie</H1>          <%= f.input :reference, placeholder: 'Referentie' %>        <br>          <%= f.label :Locatie %>        <%= f.select :location, [['Chemiepark', 'chemiepark'], ['Farmsum', 'farmsum'], ['Winschoten', 'winschoten']] %>          <br>        <%= f.input :description, placeholder: 'Omschrijving' %>        <br>        <%= f.input :date %>        <br>        <%= f.input :amount, placeholder: 'Aantal' %>        </div>        <hr>      <% if false %>          <div class="form-inputs">            <%= f.simple_fields_for :enquiry_measures do |e| %>                  <H1>Maatregelen</H1>                  <%= e.input :responsible, placeholder: 'Verantwoordelijke' %>                <br>                <%# e.input :needed, as: :check_boxes,                       collection: ["ja", "nee"] %>            <% end %>            <br>          </div>      <% end %>        <div class="form-inputs">        <%= f.simple_fields_for :tools do |t| %>            <% @enquiry.tools.each do |tool| %>                <%= field_set_tag 'Tool' do %>                    <%= f.simple_fields_for "tool_attributes[]", tool do |tf| %>                        <h1>Gereedschappen</h1>                        <br>                        <%= tf.input :handtool, placeholder: 'Handgereedschap' %>                    <% end %>                <% end %>            <% end %>        <% end %>        </div>      <div class="form-actions">        <%= f.button :submit %>      </div>  <% end %>  

The strong attributes plus what i tested:

def enquiry_params        # was gegenereerd door de scaffold params.fetch(:enquiry, {})        params.require(:enquiry).permit(:reference, :location, :description, :date, :amount,                                        :enquiry_measures_attributes => [:done, :responsible, :needed], :tools_attributes => [:handtool] )                                        #:enquiry_measures_attributes => [:done, :responsible, :needed])                                        #enquiry_measure_attributes: [:done, :responsible, :needed] )  

update code from models

class Enquiry < ActiveRecord::Base    #ophalen van andere tabellen voor het formulier. Has_many is 1 op veel relatie    #accepts_nested_attributes Nested attributes allow you to save attributes on associated records through the paren    # de dere regel zorgt ervoor dat de maatregelen worden opgehaald via de tussentabel enquiry_measures.      has_many :enquiry_measures, :class_name => 'EnquiryMeasure' #, inverse_of: :Enquiry    accepts_nested_attributes_for :enquiry_measures, :allow_destroy => true      has_many :measures, -> { uniq }, :class_name => 'Measure', :through => :enquiry_measures, dependent: :destroy    accepts_nested_attributes_for :measures, :allow_destroy => false      has_many :controls, :class_name => 'Control' #, inverse_of: :Enquiry      has_many :applicants, :class_name => 'Applicant' #, inverse_of: :Enquiry      has_many :agrees, :class_name => 'Agree' #, inverse_of: :Enquiry      has_many :signatures, :class_name => 'Signature' #, inverse_of: :Enquiry    accepts_nested_attributes_for :signatures, :allow_destroy => false      has_many :tools, :class_name => 'Tool', :dependent => :destroy  #, inverse_of: :Enquiry    accepts_nested_attributes_for :tools, :allow_destroy => true      #:dependent => :destroy  zorgt ervoor dat de foreign record ook word verwijderd.      #de instances van andere tabellen:      e = Enquiry.new    e.enquiry_measures.build(:enquiry_id => :id)    e.measures.build        # 28-11 MG de pagina's die in het form worden gebruikt.    cattr_accessor :form_steps do      %w(basic when measurements tool)    end      attr_accessor :form_step      validates :reference, presence: true, if: -> { required_for_step?(:basic) }    validates :amount, :date, presence: true, if: -> { required_for_step?(:when) }    #validates :needed, presence: true, if: -> { required_for_step?(:measurements) }      def required_for_step?(step)      return true if form_step.nil?      return true if self.form_steps.index(step.to_s) <= self.form_steps.index(form_step)    end      #voor het mailen met behulp van de mailgem:    # Declare the e-mail headers. It accepts anything the mail method    # in ActionMailer accepts.    def headers      {          :subject => "My Contact Form",          :to => "marco.groenhof@jpbgroep.nl",          :from => %("#{name}" <#{email}>)      }    end    end  

and 1 of the related models: in this case enquiry_measure

class EnquiryMeasure < ActiveRecord::Base      belongs_to :enquiry      validates_presence_of :enquiry      has_many :measure  #serialize zodat de data uit de collection select met multiple: true op kan worden geslagen.      serialize :measure    end  

and tools:

class Tool < ActiveRecord::Base    belongs_to :enquiry, :class_name => 'Enquiry' #, inverse_of: :applicant    validates_presence_of :enquiry  end  

I know class_name is not really needed anymore.

how do I change environments in ruby on rails [duplicate]

Posted: 02 Jan 2017 05:42 AM PST

This question already has an answer here:

At the moment, I am unable to run my server because apparently I seem to be in the wrong environment.

Suppose I am in the test environment, how do I switch to the production environment? Because right now, every time I am trying to run my app they keep telling me the server is running on the production environment.When I check to see if its running it still says that no application is running....

Is there a command I can use to switch environments?

`method_missing': undefined method `devise' for User error

Posted: 02 Jan 2017 04:22 AM PST

I downloaded devise in Gem of my app.When I did bundle exec rails server -b 0.0.0.0 in terminal,I got a error, .rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.5.2/lib/active_record/dynamic_matchers.rb:26:in method_missing': undefined methoddevise' for User (call 'User.connection' to establish a connection):Class (NoMethodError)

I read other error message of above error(it said user.rb:4:in <class:User>' and user.rb:1:in' were wrong)but I don't know why these sentences are wrong(because its part is devise :database_authenticatable, :registerable)

What should I do to fix this error?

I wrote , in user.rb

class User < ActiveRecord::Base    # Include default devise modules. Others available are:    # :confirmable, :lockable, :timeoutable and :omniauthable    devise :database_authenticatable, :registerable,           :recoverable, :rememberable, :trackable, :validatable  end

in migrate file,

class DeviseCreateUsers < ActiveRecord::Migration    def change      create_table(:users) do |t|        ## Database authenticatable        t.string :email,              null: false, default: ""        t.string :encrypted_password, null: false, default: ""          ## Recoverable        t.string   :reset_password_token        t.datetime :reset_password_sent_at          ## Rememberable        t.datetime :remember_created_at          ## Trackable        t.integer  :sign_in_count, default: 0, null: false        t.datetime :current_sign_in_at        t.datetime :last_sign_in_at        t.string   :current_sign_in_ip        t.string   :last_sign_in_ip          ## Confirmable        # t.string   :confirmation_token        # t.datetime :confirmed_at        # t.datetime :confirmation_sent_at        # t.string   :unconfirmed_email # Only if using reconfirmable          ## Lockable        # t.integer  :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts        # t.string   :unlock_token # Only if unlock strategy is :email or :both        # t.datetime :locked_at            t.timestamps null: false      end        add_index :users, :email,                unique: true      add_index :users, :reset_password_token, unique: true      # add_index :users, :confirmation_token,   unique: true      # add_index :users, :unlock_token,         unique: true    end  end

in application_controller

class ApplicationController < ActionController::Base    # Prevent CSRF attacks by raising an exception.    # For APIs, you may want to use :null_session instead.    before_action :authenticate_user!    protect_from_forgery with: :exception  end

in routes.rb,

Rails.application.routes.draw do        devise_for :users    get 'pages/index'      get 'pages/show'      get 'home/index'      root 'pages#index'    get 'pages/show'      get 'home/index'    root 'home#index'      namespace :connection do        get '/',action:'index'      end  end

mongoid uninitialized constant Point

Posted: 02 Jan 2017 05:37 AM PST

I hear about and try to implement those libraries mongoid-geospatial

But they all mention this class Point which is undefined for me. What am I missing ?

I am adding a geo concern to my models with ActiveSupport::Concern

module Mappable    extend ActiveSupport::Concern      included do      include Mongoid::Geospatial        field :coordinates, type: Point, spatial: true      spatial_scope :coordinates  

uninitialized constant Mappable::Point (NameError)

limit the number of stack trace lines when exception is generated in rails

Posted: 02 Jan 2017 06:15 AM PST

Is there a way i can control the number of stack trace lines generated when a exception scenario happen in a rails application.

The reason for this is i need the stack trace but not all the lines and other reason my log file grows to a huge amount after a while.

Any help would be appreciated. Thanks.

ruby map find_each can't add to array

Posted: 02 Jan 2017 04:44 AM PST

I have 2 Models: Document and Keywords. They are habtm in relation to each other and they both accepts_nested_attributes_for each other so I can create a nested form. That works well.

So in params, I have

"document"=>{"book_id"=>"1", "keywords"=>{"keywords"=>"term, administration, witness "}, ...  

In the controller I put the keywords in a separate array like this :

q = params[:document][:keywords].fetch(:keywords).split(",")  

This works well too.

What I now need to do, is get the keywords ids and put them in an array. Each element of that array will populate the join table.

I've tried this :

a = Array.new  q.each do |var|    id =  Keyword.select(:id).find_by keyword: var    a << id    id  end  

But, this only answers [#<Keyword id: 496>, nil, nil], although the server log shows that all 3 SQL requests are executed and they are correct.

I have also tried this :

a = Array.new  q.map do |e|     Keyword.where(motcle: e).select(:id).find_each do |wrd|       a << wrd.id    end  end  

Then again, this only return the FIRST id of the keyword, although the server log shows that all 3 SQL requests are executed.

What I'm trying to get is a = [496, 367, 2398]

So I have 2 questions :

1/ Why are the ids not added to the array, despite the server executing all SQL requests ?

2/ How to write in rails a request would be

SELECT  "motclefs"."id" FROM "motclefs" WHERE "motclefs"."motcle" in ('déchéances','comtesse') ORDER BY "motclefs"."id";  

Thanks !

ActiveJob spec doesn't work with ActionController::Parameters

Posted: 02 Jan 2017 06:30 AM PST

My test:

describe TasksCsvsController do    describe '#index' do      let(:params) { {'clients' => {'id' => ['1', '2', '3']}} }        before do        ActiveJob::Base.queue_adapter = :test      end        it 'enqueues tasks csv job' do        get :create, params: params        expect(ProjectsCsvJob).to have_been_enqueued.with(params['clients'])      end    end  end  

The controller it tests:

class TasksCsvsController < ApplicationController    def create      ProjectsCsvJob.perform_now(csv_params.to_unsafe_hash)      redirect_to tasks_path, notice: I18n.t('flashes.tasks_csv_generating', email: current_user.email)    end      private      def csv_params      params.require(:clients).permit(:from, :to, tasks_grid: {}, id: [])    end  end  

And the ActiveJob:

class ProjectsCsvJob < ApplicationJob    queue_as :default      def perform(clients_params)      # it does nothing    end  end  

The test doesn't pass:

Failure/Error: expect(ProjectsCsvJob).to have_been_enqueued.with(params['clients'])         expected to enqueue exactly 1 jobs, with [{"id"=>["1", "2", "3"]}], but enqueued 0  

This is strange, because when I debug during the test, params['clients'].to_unsafe_hash is what I expect.

However, when I change the controller's line to

ProjectsCsvJob.perform_later({'id' => ['1', '2', '3']})  

the test passes.

Customize index action in ActiveAdmin

Posted: 02 Jan 2017 07:30 AM PST

I have more than 5 million records in the table (Phone). When I click on Phone Table, It takes more then 5 min. to display a records and on heroku it's going to crash.

I want to customize my index action. I just want to display 10,000 records and other records will be display as per the search query.

How can I do this?

I tried following but it gives me error.

raise ArgumentError, "First argument in form cannot contain nil or be empty" unless object

 controller do      def index          @phones = Phone.limit(10000).page(params[:page])      end        def permitted_params        params.permit!       end    end  

Ruby-on-rails web application could not be started because of 'uglifier'

Posted: 02 Jan 2017 04:02 AM PST

There was an error while trying to load the gem 'uglifier'.

Gem Load Error is: wrong argument type Class (expected Module)  Backtrace for gem load error is:    /usr/local/lib/ruby/gems/2.4.0/gems/therubyracer-0.12.2/lib/v8/conversion.rb:23:in `include'  /usr/local/lib/ruby/gems/2.4.0/gems/therubyracer-0.12.2/lib/v8/conversion.rb:23:in `block (2 levels) in <top (required)>'  /usr/local/lib/ruby/gems/2.4.0/gems/therubyracer-0.12.2/lib/v8/conversion.rb:22:in `class_eval'  /usr/local/lib/ruby/gems/2.4.0/gems/therubyracer-0.12.2/lib/v8/conversion.rb:22:in `block in <top (required)>'  /usr/local/lib/ruby/gems/2.4.0/gems/therubyracer-0.12.2/lib/v8/conversion.rb:21:in `each'  /usr/local/lib/ruby/gems/2.4.0/gems/therubyracer-0.12.2/lib/v8/conversion.rb:21:in `<top (required)>'  /usr/local/lib/ruby/gems/2.4.0/gems/therubyracer-0.12.2/lib/v8.rb:22:in `require'  /usr/local/lib/ruby/gems/2.4.0/gems/therubyracer-0.12.2/lib/v8.rb:22:in `<top (required)>'  /usr/local/lib/ruby/gems/2.4.0/gems/execjs-2.7.0/lib/execjs/ruby_racer_runtime.rb:108:in `require'  /usr/local/lib/ruby/gems/2.4.0/gems/execjs-2.7.0/lib/execjs/ruby_racer_runtime.rb:108:in `available?'  /usr/local/lib/ruby/gems/2.4.0/gems/execjs-2.7.0/lib/execjs/runtimes.rb:63:in `each'  /usr/local/lib/ruby/gems/2.4.0/gems/execjs-2.7.0/lib/execjs/runtimes.rb:63:in `find'  /usr/local/lib/ruby/gems/2.4.0/gems/execjs-2.7.0/lib/execjs/runtimes.rb:63:in `best_available'  /usr/local/lib/ruby/gems/2.4.0/gems/execjs-2.7.0/lib/execjs/runtimes.rb:57:in `autodetect'  /usr/local/lib/ruby/gems/2.4.0/gems/execjs-2.7.0/lib/execjs.rb:5:in `<module:ExecJS>'  /usr/local/lib/ruby/gems/2.4.0/gems/execjs-2.7.0/lib/execjs.rb:4:in `<top (required)>'  /usr/local/lib/ruby/gems/2.4.0/gems/uglifier-3.0.4/lib/uglifier.rb:5:in `require'  /usr/local/lib/ruby/gems/2.4.0/gems/uglifier-3.0.4/lib/uglifier.rb:5:in `<top (required)>'  /usr/local/lib/ruby/gems/2.4.0/gems/bundler-1.13.7/lib/bundler/runtime.rb:91:in `require'  /usr/local/lib/ruby/gems/2.4.0/gems/bundler-1.13.7/lib/bundler/runtime.rb:91:in `block (2 levels) in require'  /usr/local/lib/ruby/gems/2.4.0/gems/bundler-1.13.7/lib/bundler/runtime.rb:86:in `each'  /usr/local/lib/ruby/gems/2.4.0/gems/bundler-1.13.7/lib/bundler/runtime.rb:86:in `block in require'  /usr/local/lib/ruby/gems/2.4.0/gems/bundler-1.13.7/lib/bundler/runtime.rb:75:in `each'  /usr/local/lib/ruby/gems/2.4.0/gems/bundler-1.13.7/lib/bundler/runtime.rb:75:in `require'  /usr/local/lib/ruby/gems/2.4.0/gems/bundler-1.13.7/lib/bundler.rb:106:in `require'  /var/www/geia.junyuzhu.com/public_html/testapp/config/application.rb:7:in `<top (required)>'  /var/www/geia.junyuzhu.com/public_html/testapp/config/environment.rb:2:in `require_relative'  /var/www/geia.junyuzhu.com/public_html/testapp/config/environment.rb:2:in `<top (required)>'  config.ru:3:in `require_relative'  config.ru:3:in `block in <main>'  /usr/local/lib/ruby/gems/2.4.0/gems/rack-2.0.1/lib/rack/builder.rb:55:in `instance_eval'  /usr/local/lib/ruby/gems/2.4.0/gems/rack-2.0.1/lib/rack/builder.rb:55:in `initialize'  config.ru:1:in `new'  config.ru:1:in `<main>'  /usr/share/passenger/helper-scripts/rack-preloader.rb:110:in `eval'  /usr/share/passenger/helper-scripts/rack-preloader.rb:110:in `preload_app'  /usr/share/passenger/helper-scripts/rack-preloader.rb:156:in `<module:App>'  /usr/share/passenger/helper-scripts/rack-preloader.rb:30:in `<module:PhusionPassenger>'  /usr/share/passenger/helper-scripts/rack-preloader.rb:29:in `<main>'  Bundler Error Backtrace:   (Bundler::GemRequireError)    /usr/local/lib/ruby/gems/2.4.0/gems/bundler-1.13.7/lib/bundler/runtime.rb:94:in `rescue in block (2 levels) in require'    /usr/local/lib/ruby/gems/2.4.0/gems/bundler-1.13.7/lib/bundler/runtime.rb:90:in `block (2 levels) in require'    /usr/local/lib/ruby/gems/2.4.0/gems/bundler-1.13.7/lib/bundler/runtime.rb:86:in `each'    /usr/local/lib/ruby/gems/2.4.0/gems/bundler-1.13.7/lib/bundler/runtime.rb:86:in `block in require'    /usr/local/lib/ruby/gems/2.4.0/gems/bundler-1.13.7/lib/bundler/runtime.rb:75:in `each'    /usr/local/lib/ruby/gems/2.4.0/gems/bundler-1.13.7/lib/bundler/runtime.rb:75:in `require'    /usr/local/lib/ruby/gems/2.4.0/gems/bundler-1.13.7/lib/bundler.rb:106:in `require'    /var/www/geia.junyuzhu.com/public_html/testapp/config/application.rb:7:in `<top (required)>'    /var/www/geia.junyuzhu.com/public_html/testapp/config/environment.rb:2:in `require_relative'    /var/www/geia.junyuzhu.com/public_html/testapp/config/environment.rb:2:in `<top (required)>'    config.ru:3:in `require_relative'    config.ru:3:in `block in <main>'    /usr/local/lib/ruby/gems/2.4.0/gems/rack-2.0.1/lib/rack/builder.rb:55:in `instance_eval'    /usr/local/lib/ruby/gems/2.4.0/gems/rack-2.0.1/lib/rack/builder.rb:55:in `initialize'    config.ru:1:in `new'    config.ru:1:in `<main>'    /usr/share/passenger/helper-scripts/rack-preloader.rb:110:in `eval'    /usr/share/passenger/helper-scripts/rack-preloader.rb:110:in `preload_app'    /usr/share/passenger/helper-scripts/rack-preloader.rb:156:in `<module:App>'    /usr/share/passenger/helper-scripts/rack-preloader.rb:30:in `<module:PhusionPassenger>'    /usr/share/passenger/helper-scripts/rack-preloader.rb:29:in `<main>'  

I have tried to install nodejs and restart the apache server. It doesn't help with this issue.

bundle show uglifier gives

/usr/local/lib/ruby/gems/2.4.0/gems/uglifier-3.0.4  

I assume I have uglifier installed correctly.

Also gem 'therubyracer', platforms: :ruby is uncommented in Gemfile.

Please help, I have no idea how to solve this issue.

close zelect dropdown on click of a sibling

Posted: 02 Jan 2017 07:20 AM PST

I have following html code ( Rails erb view )-

<%= select_tag :destination, options_for_select(@destinations, params["destination"]), :id => 'destination', :style => 'width:100%;' %>  <div class='dropdown-icon destination-icon'>   <i class='fa fa-chevron-down'></i>  </div>  

& following js code -

  $(document).click(function(){      $('.zelect').removeClass("open");      $('.zelect .dropdown').hide();    })      $('.zelect').click(function(e){      e.stopPropagation();    })      $('.dropdown-icon.destination-icon').click(function(e){      var zelect = $(this).siblings(".zelect");      if( zelect.hasClass("open") ){        zelect.removeClass("open");        zelect.children(".dropdown").hide();      }      else{        zelect.addClass("open");        zelect.children(".dropdown").show();                  }        });    

What I want to do is close zelect dropdown on clicking anywhere except for zelect input & destination-icon.

How do I do it ?

Adding raygun to app X would overwrite existing vars RAYGUN_APIKEY (Ruby on Rails)

Posted: 02 Jan 2017 03:21 AM PST

I am trying to add Raygun to a new RoR Heroku app X, but it says "Item could not be created: Adding raygun to app X would overwrite existing vars RAYGUN_APIKEY".

I deleted the old RAYGUN_APIKEY api key and it does not show in the heroku list of keys (figaro heroku:set -e production), but it seems that heroku still finds this key.

How could I fix this issue?

Ajax not working inside iteration

Posted: 02 Jan 2017 04:15 AM PST

I have a AtpRank model containing the first 100 Atp tennis players.
My goal is to create in the view a table listing all tennis players and their attributes, along with a button for each player useful for the user to choose a list of tennis players. The home.html.erb code is below:

<% @atp_ranks.each do |tennis_player| %>    <tr id="tennist-<%= tennis_player.ranking %>">      <td class="atpranking"> <%= tennis_player.ranking %> </td>      <td class="atpname"> <%= tennis_player.name %> </td>      <td class="atppoints"> <%= tennis_player.points %> </td>      <% unless Time.now.month == 12 %>        <td>          <div id="atpenlist_form">            <% if current_user.atpenlisted?(tennis_player) %>              <%= form_for(current_user.atp_selections.find_by(atp_rank_id: tennis_player.id),                                                   html: { method: :delete }, remote: true) do |f| %>                <%= f.submit "Dump", class: "btn btn-warning btn-sm" %>              <% end %>            <% else %>              <%= form_for(current_user.atp_selections.build, remote: true) do |f| %>                <div><%= hidden_field_tag :atp_id, tennis_player.id %></div>                <%= f.submit "Choose", class: "btn btn-primary btn-sm" %>              <% end %>            <% end %>          </div>        </td>      <% end %>    </tr>  <% end %>  

As you can see, the form uses Ajax having set remote: true in the form_for helper. Requests are handled by the atp_selections controller. Below is an extract of the create action of this controller:

    current_user.atpenlist(tennist)      respond_to do |format|        format.html { redirect_to root_url }        format.js      end  

The destroy action uses the atpdiscard method instead of the atpenlist method.
In app/views/atp_selections I created the create.js.erb and destroy.js.erb files.
Below is the app/views/atp_selections/create.js.erb file:

$("#atpenlist_form").html("<%= escape_javascript(render('users/atpdiscard')) %>");  $("#atp_count").html('<%= current_user.atp_ranks.count %>');  

Each of the app/view/users/_atpenlist.html.erb and app/view/users/_atpdiscard.html.erb partials contain the respective form (the same exact part of the code above starting with form_for).

I have to say that in the original code for the home page I did not explicitly included the entire code for the forms, but I just rendered the partials. This did not work: rails warned me that it could not find the variable or method tennis_player used in the iteration, for some reason to me unknown. So I had to renounce to render the partials and decided to include the entire code.

The issue is now that Ajax does not work: I have to refresh the page to see the results of submitting the form. I checked my code and could not find errors or explanation for this.

How to fix the pluralization for comments and likes in rails

Posted: 02 Jan 2017 06:34 AM PST

I am new to rails, and i am working on a rtl website in Arabic! I am trying to fix the pluralization in comment.count and get_upvotes.size to be replaced by the arabic words. I have heard the I can do it with Rails Internationalization (I18n) but I could not find a clear answer to my question.

I would appreciate the help. Let me know if more information is needed! Thanks

ERROR: Error installing mysql2: ERROR: Failed to build gem native extension. on Mac 10.12

Posted: 02 Jan 2017 03:17 AM PST

I tried every solution similar to the question:

Recently , I moved from ubuntu to Mac and I'm trying to install mysql gem on Sierra and after I had installed Ruby , Rails , Mysql,

also I type brew install mysql and it worked for download mysql but not the gem , so my question is not similar.

I typed this mysql --version

and I got mysql Ver 14.14 Distrib 5.7.16, for osx10.12 (x86_64) using EditLine wrapper

I tried to install mysql2 gem for rails to build a new app

I typed this sudo gem install mysql2 and got this error:

Password:  Building native extensions.  This could take a while...  ERROR:  Error installing mysql2:  ERROR: Failed to build gem native extension.    current directory: /Users/mohammed.elias/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/mysql2-0.4.5/ext/mysql2  /Users/mohammed.elias/.rbenv/versions/2.4.0/bin/ruby -r ./siteconf20170102-2045-18gcs95.rb extconf.rb  checking for rb_absint_size()... yes  checking for rb_absint_singlebit_p()... yes  checking for ruby/thread.h... yes  checking for rb_thread_call_without_gvl() in ruby/thread.h... yes  checking for rb_thread_blocking_region()... no  checking for rb_wait_for_single_fd()... yes  checking for rb_hash_dup()... yes  checking for rb_intern3()... yes  checking for rb_big_cmp()... yes  -----  Using mysql_config at /usr/local/bin/mysql_config  -----  checking for mysql.h... yes  checking for SSL_MODE_DISABLED in mysql.h... yes  checking for SSL_MODE_PREFERRED in mysql.h... yes  checking for SSL_MODE_REQUIRED in mysql.h... yes  checking for SSL_MODE_VERIFY_CA in mysql.h... yes  checking for SSL_MODE_VERIFY_IDENTITY in mysql.h... yes  checking for errmsg.h... yes  checking for mysqld_error.h... yes  -----  Don't know how to set rpath on your system, if MySQL libraries are not in path mysql2 may not load  -----  -----  Setting libpath to /usr/local/Cellar/mysql/5.7.16/lib  -----  creating Makefile    To see why this extension failed to compile, please check the mkmf.log which can be found here:      /Users/mohammed.elias/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/extensions/x86_64-darwin-16/2.4.0-static/mysql2-0.4.5/mkmf.log    current directory:     /Users/mohammed.elias/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/mysql2-0.4.5/ext/mysql2  make "DESTDIR=" clean    current directory:     /Users/mohammed.elias/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/mysql2-0.4.5/ext/mysql2  make "DESTDIR="  compiling client.c  compiling infile.c  compiling mysql2_ext.c  compiling result.c  compiling statement.c  linking shared-object mysql2/mysql2.bundle  ld: library not found for -lssl  clang: error: linker command failed with exit code 1 (use -v to see invocation)  make: *** [mysql2.bundle] Error 1    make failed, exit code 2    Gem files will remain installed in     /Users/mohammed.elias/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/mysq l2-0.4.5 for inspection.  Results logged to     /Users/mohammed.elias/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/extensions/x86_64-darwin-16/2.4.0-static/mysql2-0.4.5/gem_make.out  

Undefined variable: "$global-breakpoint" wherever stylesheet_link_tag and javascript_link_tag is mentioned

Posted: 02 Jan 2017 02:39 AM PST

I have recently upgraded my Rails 3.2 application to Rails 5. After managing to run the application when I tried to access some pages this is the error I encountered:

Undefined variable: "$global-breakpoint".    Extracted source (around line #2)    <div ng-controller="navigationController">  <%= stylesheet_link_tag 'header_b2c', media: 'all', 'data-turbolinks-track' => true %>  <% current_user = nil unless defined?(current_user) %>  

This is happening at all the places wherever I am using the stylesheet_link_tag or javascript_link_tag. The header_b2c in the case above is a normal css file in the assets/stylesheets directory.

The same code used to work in rails 3.2. Searching for the error yields almost no result, is it something related to a config thing that I need to do in order to make the css files get interpreted as a css file instead of a sass file ? If not, what else might be the issue ?

NoMethodError in ConnectionController#index

Posted: 02 Jan 2017 02:38 AM PST

When I access localhost:3000, my browser told error of NoMethodError in ConnectionController#index. Also,I was told that undefined method `action' for ConnectionController(Table doesn't exist):Class.

The error browser told connection_controller.rb of 26 line was wrong but I didn't write codes so long like 26 lines.

 send(name, *arguments, &block)        else          super        end      end

I wrote ,in connection_controller.rb

class ConnectionController <  ActiveRecord::Base      def index          personal = {'name'=>'Yamada','old'=>28}          render :json => personal        end  end

in routes.rb,

Rails.application.routes.draw do        namespace :connection do        get '/',action:'index'      end  end

in schema.rb

ActiveRecord::Schema.define(version: 20170101073143) do      create_table "userdata", force: :cascade do |t|      t.datetime "created_at", null: false      t.datetime "updated_at", null: false    end    end

in migrate file ,

class CreateUserdata < ActiveRecord::Migration    def change      create_table :userdata do |t|       t.string :name        t.text :image        t.timestamps null: false      end    end  end

in model,

class Userdatum < ActiveRecord::Base  	user = User.new  	user.name = "XXX"  	user.email = "mail"  	user.save  end

Postgres permission denied for relation schema_migrations

Posted: 02 Jan 2017 02:02 AM PST

Busy getting a PG DB working using a db user called shine. Following the book Rails, Angular, Postgres and Bootstrap: I initiated with:

createuser --createdb --login -P shine

bundle exec rails db:create

works.

bundle exec rails db:migrate

gives:

bundle exec rails db:migrate  rails aborted!  ActiveRecord::StatementInvalid: PG::InsufficientPrivilege: ERROR:  permission denied for relation schema_migrations  : SELECT "schema_migrations".* FROM "schema_migrations"  bin/rails:4:in `require'  bin/rails:4:in `<main>'  PG::InsufficientPrivilege: ERROR:  permission denied for relation schema_migrations  bin/rails:4:in `require'  bin/rails:4:in `<main>'  Tasks: TOP => db:migrate  (See full trace by running task with --trace)  

in psql \list gives:

shine_development              | shine       | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =Tc/shine                  +                                  |             |          |             |             | shine=CTc/shine   shine_test                     | shine       | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =Tc/shine                  +                                  |             |          |             |             | shine=CTc/shine  

I have tried all the ALTER, GRANT and OWNER TO commands I could pretty much find out there. What's going on?

database.yml

default: &default    adapter: postgresql    encoding: unicode    host: localhost    username: shine    password: shine    pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>    development:    <<: *default    database: shine_development

Missing files in Ubuntu bash on Windows 10

Posted: 02 Jan 2017 02:00 AM PST

Im running Ubuntu bash on Windows 10 and I have an issue with files not showing in Bash while they exist in my Windows 10 environment.

For example when i run the ls command i get the following:

application.html.haml mailer.html.haml mailer.text.haml

I'm missing a folder there (shared). When i go to this very same folder in Windows i see the following: enter image description here

How is it possible Bash is not showing these files? When i run my rails app i get an error for a missing partial file, which is located in the sharedfolder.

This is my gemfile:

gem 'rails', '~> 5.0.1'  gem 'sqlite3'  gem 'puma', '~> 3.0'  gem 'sass-rails', '~> 5.0'  gem 'uglifier', '>= 1.3.0'  gem 'coffee-rails', '~> 4.2'    gem 'jquery-rails'  gem 'turbolinks', '~> 5'  gem 'jbuilder', '~> 2.5'    gem 'haml'  gem 'bootstrap-sass', '~> 3.3.6'  gem 'devise'  gem 'awesome_print', :require => 'ap'  gem "select2-rails"  gem 'font-awesome-rails'  gem 'omni_kassa'  gem 'seed_dump'  gem 'jquery-datetimepicker-rails'  gem "cancan"  gem 'binding_of_caller'    group :development, :test do    gem 'byebug', platform: :mri  end    group :development do    gem 'web-console', '>= 3.3.0'    gem 'listen', '~> 3.0.5'      gem 'spring'    gem 'spring-watcher-listen', '~> 2.0.0'      gem 'erb2haml'    gem 'annotate', "~> 2.6.5"    gem 'better_errors'  end  

Rails: Byebug doesn't print in console

Posted: 02 Jan 2017 03:17 AM PST

From some unknown reasons, Byebug stops printing code in console.

For example, I've added byebug in following test:

enter image description here

What I've got in console / terminal:

enter image description here

Do you have any idea what could be wrong or where could I search for a reason of this problem?

EDIT:

Command how I run tests:

$ rake spec  

EDIT 2:

When I run server with Byebug in any place it also doesn't work. It even doesn't print any logs. This is how does it look console after running server and sending to them some requests - ... empty:

enter image description here

That does it doesn't print in console could be caused by puma.rb configuration:

min_threads_count = ENV.fetch('RAILS_MIN_THREADS') { 5 }.to_i  max_threads_count = ENV.fetch('RAILS_MAX_THREADS') { 5 }.to_i  threads min_threads_count, max_threads_count    bind "unix:///var/run/puma.sock?umask=0000"    stdout_redirect "/var/log/puma.stdout.log", "/var/log/puma.stderr.log", true    environment ENV.fetch('RAILS_ENV') { 'development' }    plugin :tmp_restart  

ActiveRecord callback or MySql trigger?

Posted: 02 Jan 2017 05:47 AM PST

Lets say we have two models:

class Message < ActiveRecord::Base    belongs_to :user    has_many :statistics  end    class Statistic < ActiveRecord::Base    belongs_to :user    belongs_to :messages  end  

The Message has :state attribute and it has to be updated based on Statistic counts (i.g. delivered_at, read_at). Meaning once the message was delivered to every user in the group the state has to be updated accordingly.
The Statistics timestamps updated in a sidekiq jobs with a query that does not invoke the callback (update_all) so I can't hook into 'after_update' callback of the Statistics and update the Message.state.
I've tried to do it using MySql after update trigger on Statistics table but had no luck because the query that invokes the trigger has the destination table (messages) in join.
Please advise.
Hope I was clear enough.
Thank you.

Rails: Enable users to choose their roles when signing up on devise

Posted: 02 Jan 2017 01:49 AM PST

I'm using devise for my Rails project to authenticate users. There are several roles that users can choose from (e.g. admin, student, teacher), and I want the users to be able to choose their role when signing up.

I've searched around and found ways to set a default role and enable users to change that role later, but I couldn't find a good resource for how to modify the devise controller and view to allow users to choose their role right away.

Can someone point me to a tutorial or something that they know would be helpful?

Terminal does not work after running rails server

Posted: 02 Jan 2017 01:40 AM PST

after running "rails server" on my mac to start my application, my terminal does not allow me to write commands in the terminal. All I get is the following, with the problem that I can not write any commands.

Last login: Mon Jan  2 13:19:07 on ttys001  Nicholass-MacBook-Pro:~ nicholaswenzel$ cd last_test  Nicholass-MacBook-Pro:last_test nicholaswenzel$ cd nofuckingidea  Nicholass-MacBook-Pro:nofuckingidea nicholaswenzel$ rails s  => Booting WEBrick  => Rails 4.2.6 application starting in development on http://localhost:3000  => Run `rails server -h` for more startup options  => Ctrl-C to shutdown server  [2017-01-02 13:23:18] INFO  WEBrick 1.3.1  [2017-01-02 13:23:18] INFO  ruby 2.2.3 (2015-08-18) [x86_64-darwin15]  [2017-01-02 13:23:18] INFO  WEBrick::HTTPServer#start: pid=8743 port=3000  

Can anyone help?

Work around CORS Ember error for a Rails backend

Posted: 02 Jan 2017 12:14 AM PST

Building a front end interface using a Rails REST API, I get the error

XMLHttpRequest cannot load http://www.example.com/questions  No 'Access-Control-Allow-Origin' header is present on the requested   resource. Origin 'http://localhost:4200' is therefore not allowed access.  

I've set up my adapter to be

import DS from 'ember-data';    export default DS.RESTAdapter.extend({    namespace: 'api/v1',    host: 'http://www.example.com'  });  

If I was building the API, I would just include the gem 'rack-cors' and allow for the access to other sites, but this is not included in the source. I'm just starting out with the Ember framework and haven't yet found a work around for this.

I've tried running a proxy server

ember s --proxy http://www.example.com  

But I get the same response. Is there a piece of middleware or a method on the RESTAdapter that I can use to bypass this error?

No comments:

Post a Comment