Wednesday, July 20, 2016

Spree 2.4-stable NoMethodError: undefined method `environment=' for # | Fixed issues

Spree 2.4-stable NoMethodError: undefined method `environment=' for #<Spree::Gateway::Bogus:0x007fe70b00ad80> | Fixed issues


Spree 2.4-stable NoMethodError: undefined method `environment=' for #<Spree::Gateway::Bogus:0x007fe70b00ad80>

Posted: 20 Jul 2016 07:39 AM PDT

Getting this error while trying to load sample data

NoMethodError: undefined method `environment=' for Spree::Gateway::Bogus:0x007fe70b00ad80

My Spree version is 2.4-stable ruby 2.2.1 and rails 4.1.8 Please suggest solution.

ActiveRecord::AssociationTypeMismatch gotNilClass

Posted: 20 Jul 2016 07:28 AM PDT

I am a beginner programmer in Ruby and Ruby on Rails , I'm trying to run a rake command in my task , but when I do the following happens:

rake daily_tasks:process_api  

rake aborted! ActiveRecord::AssociationTypeMismatch: State(#47392639701120) expected, got NilClass(#47392580444120) /home/thiagoamaralr/Desktop/proponente-master-74f8a3b2ddb02a90b2c173cf31383505018d02dd/app/services/create_programa_api.rb:21:in call' /home/thiagoamaralr/Desktop/proponente-master-74f8a3b2ddb02a90b2c173cf31383505018d02dd/lib/tasks/daily_tasks.rake:7:inblock (3 levels) in ' /home/thiagoamaralr/Desktop/proponente-master-74f8a3b2ddb02a90b2c173cf31383505018d02dd/lib/tasks/daily_tasks.rake:5:in each' /home/thiagoamaralr/Desktop/proponente-master-74f8a3b2ddb02a90b2c173cf31383505018d02dd/lib/tasks/daily_tasks.rake:5:inblock (2 levels) in ' Tasks: TOP => daily_tasks:process_api (See full trace by running task with --trace)

Follow the task I'm trying to run:

namespace :daily_tasks do  

desc "Process the day to day tasks" task process_api: :environment do

SiconvApi::Programa.find.each do |programa|    if programa.data_inicio_recebimento_propostas && (programa.data_inicio_recebimento_propostas.to_date >= Date.parse("2015/06/01"))      CreateProgramaApi.call(SiconvApi::Serializers::Programa.new(programa))    end  end  

Thank you in advance for your attention!

Using secret passwords in Rails App

Posted: 20 Jul 2016 07:44 AM PDT

I am working on a rails application, on which I need to send an issue on github if a certain process takes place. To send a post request, I need to use my github username and password. I can't use my password in open. What should I do?

I know something about secrets.yml file in rails config but I can't even put my password there. I will put my app on github and anyone can hence access. How should I use secrets.yml file to store my password and use it in my rails app?

Testing successful seed with minitest / rspec

Posted: 20 Jul 2016 07:42 AM PDT

I'm trying to test if a seed is successfully run. I currently have the following:

require 'test_helper'    class SeedsTest < ActiveSupport::TestCase    test 'it should successfully run the seeds' do      assert_nothing_raised(Exception) { load Rails.root.join('db/seeds.rb') }    end  end  

However the load expression simply returns true and does not invoke the seed. Is there a way to do this?

edit: I tried running it as a rake test, but it gave me the same.

assert_nothing_raised(Exception) { Rake::Task["db:seed"].invoke }  

Getting nilClass error while testing with rspec

Posted: 20 Jul 2016 07:17 AM PDT

Hi i'm testing my project with rspec and now i'm up to the controllers part. I'm testing this method:

 def accept  @app = App.find(params[:id])  @invite = Invite.find_by(app: @app.name, receiver: current_dev.id)  @dev = Developer.find(@invite.sender)  @app.developers << @dev  respond_to do |format|    if @invite.destroy      format.html { redirect_to @app, notice: 'A new developer joined your team!' }      format.json { render :show, status: :destroyed, location: @app }    else      format.html { render :back }      format.json { render json: @invite.errors, status: :unprocessable_entity }    end  end  end  

and this is the test part:

    it "should accept an invite (1)" do        invite = Invite.create(:app => "test", :sender => "2", :receiver => "1")      get :accept, :id => 1      assert_response :success    end  

but when i run the rspec command i get this error:

   InvitesController should accept an invite (1)   Failure/Error: @dev = Developer.find(@invite.sender)     NoMethodError:     undefined method `sender' for nil:NilClass  

So i am assuming that the invite object is nil but i can't figure out why this happens. I test the function via browser and everything works fine. This is also causing same errors in different controller methods, everytime just because my invite object is nil. Why is this happening? Sorry for my english and for the post in general, very first time asking here.

Function to synchronize two ERB select elements

Posted: 20 Jul 2016 07:10 AM PDT

I have two ERB select elements. One is in a form as follows, (using the Chosen gem for UI styling):

<%= fields_for @education_plan do |f| %>      <%= first_error_tag(@education_plan, :education_plan_provinces) %>      <%= f.select :province_ids,        (DataHelper::all_provinces_captions.zip(DataHelper::all_provinces_ids)),                       { include_blank: true }, {class: 'chosen-select',                        multiple: true, data: {placeholder: 'Filter Provinces/States'} }      %>  <% end %>  

My other selector is just an ERB select_tag:

<%= select_tag :provinces, options_for_select(DataHelper::all_provinces_captions.zip(DataHelper::all_provinces_captions)), {:multiple => true, class: 'chosen-select', :data => {:placeholder => 'Filter Provinces/States'}}%>  

Is there a way to synchronize the selections of select_tag :provinces to f.select :province_ids, with Javascript/Jquery?

importing a CSV and assign to current user ruby

Posted: 20 Jul 2016 07:07 AM PDT

I am trying to import a CSV file and assign the import to the current user. So, it will add the user_id to the each row of the csv import.

I am missing something because it still doesn't find the user and add it to the row...

Controller :

 def import      Inventory.import(params[:file], current_user.id)      redirect_to root_url, notice: "Inventory imported."    end  

Method:

class Inventory < ApplicationRecord      belongs_to :user    def self.import(file, user_id)    allowed_attributes = [ "user_id", "id","description","part_number","price","created_at","updated_at", "alternate_part_number", "condition_code", "qty", "mfg_code", "serial_number", "part_comments"]    spreadsheet = open_spreadsheet(file)    header = spreadsheet.row(1)    (2..spreadsheet.last_row).each do |i|      row = Hash[[header, spreadsheet.row(i)].transpose]      inventory = find_by_id(row["id"]) || new      inventory.attributes = row.to_hash.select { |k,v| allowed_attributes.include? k }      inventory.save!    end  end  

I end up with this error: import error ruby

Thank you for any help!!

Rails how to pass parse data from sql view to model?

Posted: 20 Jul 2016 07:38 AM PDT

I followed the excellent post from Frank Rietta about "Adding a Rake Task for SQL Views to a Rails Project". I like his point of view about database views in rails and his dry approach.

I am able to do rake db:views and my view is created but I am not able to get the information in the model, this is my models/reports/revenue.rb

class Report::Revenue < ApplicationRecord    self.table_name = 'report_revenues'  end  

I changed the extension because I am using Rails 5.0.0

If I execute the rails console --sandbox and there I execute Report::Revenue I get the following

2.3.1 :004 > Report::Revenue  NameError: uninitialized constant Report  

I am not sure what I am missing

Reform: Dry-Validation Matchers

Posted: 20 Jul 2016 07:02 AM PDT

I'm looking for a convenient way to test validations of a Reform-based form object.

Are there any matchers (like shoulda matchers for testing ActiveModel::Validations) to test dry-validations? Is this even the way to go?

Generating charts using SpreadsheeML

Posted: 20 Jul 2016 06:41 AM PDT

I am currently using SpreadsheetML in rails for generating excel sheet. Upto now, its working fine, as the data types are just string and numbers. Now, I am looking forward to generate the chart in excel sheet, based upon the numbers. So is it possible to generate the chart using SpreadsheetML tags, based upon the numbers? If not, can I have image datatype in SpreadsheetML? Any help would be appreciated...

rake aborted! NameError: uninitialized constant even add :enviroment to task

Posted: 20 Jul 2016 07:19 AM PDT

I'm newbie to RoR and trying to create a task to import database from google spreadsheet by creating an Importer under lib/spreadsheet. but rake cannot find my importer even I added :environment to task according to some others issues in SOF. here are my files

lib/spreadsheet/importer.rb

class SpreadSheet::Importer    def initialize      @session = GoogleDrive.saved_session("#{Rails.root}/config/google_drive/config.json")    end      def exec(table_name)      #do something    end  end  

lib/tasks/spreadsheet.rake

namespace :spreadsheet do    task :get => :environment do      importer = Spreadsheet::Importer.new      importer.exec    end  end  

Error:

rake aborted!

NameError: uninitialized constant SpreadSheet

/home/vagrant/workspace/ruby/kuwata-summer/lib/tasks/spreadsheet.rake:1:in <top (required)>

/home/vagrant/workspace/ruby/kuwata-summer/vendor/bundle/ruby/2.3.0 /gems/railties-5.0.0/lib/rails/engine.rb:654:in block in run_tasks_blocks

/home/vagrant/workspace/ruby/kuwata-summer/vendor/bundle/ruby/2.3.0/gems/railties-5.0.0/lib/rails/engine.rb:654:in each

/home/vagrant/workspace/ruby/kuwata-summer/vendor/bundle/ruby/2.3.0/gems/railties-5.0.0/lib/rails/engine.rb:654:in run_tasks_blocks

/home/vagrant/workspace/ruby/kuwata-summer/vendor/bundle/ruby/2.3.0/gems/railties-5.0.0/lib/rails/application.rb:443:in run_tasks_blocks

/home/vagrant/workspace/ruby/kuwata-summer/vendor/bundle/ruby/2.3.0/gems/railties-5.0.0/lib/rails/engine.rb:457:in load_tasks

/home/vagrant/workspace/ruby/kuwata-summer/rakefile:6:in <top (required)>

/home/vagrant/workspace/ruby/kuwata-summer/vendor/bundle/ruby/2.3.0/gems/rake-11.2.2/exe/rake:27:in <top (required)>

/home/vagrant/.rbenv/versions/2.3.1/bin/bundle:23:in load

/home/vagrant/.rbenv/versions/2.3.1/bin/bundle:23:in <main>

(See full trace by running task with --trace)

rails activerecord prepared statement

Posted: 20 Jul 2016 06:53 AM PDT

The project that I am working on uses rails 4.0.2 and postgress 9.4.7 I am new to rails and I wonder if rails active record creates prepend statement

When I run this line:

 User.where(id:123)  

The log says:

 SELECT "users".* FROM "users" WHERE "users"."id" = 123  

But when I run this line:

When I run this line:

 User.find(123)  

The log says:

 SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT 1  [["id", 123]]  

Why is the difference? Which is more secure? I think that that first version using where() is only escaping the data and the second version using find() uses prepend statement is that correct? Is it possible to use where but to create a query like the second version?

How to prevent writing 'object' field in PaperTrail

Posted: 20 Jul 2016 06:00 AM PDT

  1. I have many fields in my table, I don't want to version all columns. How do I skip the columns which I don't need to store any changes

I have used the following, but it stores the values in 'versions' table. In my model

class User < ActiveRecord::Base    has_paper_trail skip: [:foo1, :foo2, :foo3]    # tried with ignore instead of skip  end  
  1. How do I prevent writing object field in 'versions' table.

How to disable multiple callbacks in Rails 4?

Posted: 20 Jul 2016 07:37 AM PDT

I have different callbacks for all my models. For a particular task I want to disable all callbacks not individually disable it.

 ActiveRecord::Base.descendants.each do |model|     model.skip_callback(:create)   end  

Can I do something like this to disable all callbacks

Edit: I tried doing this and it worked

 ActiveRecord::Base.descendants.each do |model|     model.reset_callbacks :save     model.reset_callbacks :commit     model.reset_callbacks :update     model.reset_callbacks :validate   end  

Only problem is now how do I enable them back once the task is done

Disable drop up on Rails form - bootstrap

Posted: 20 Jul 2016 06:27 AM PDT

I'm trying to prevent Bootstrap's automatic drop up from occurring on smaller screen sizes.

The S.O. question here says to add to add the attribute data-dropup-auto and set it to false, however upon doing so it doesn't work. Inspecting the select drop down from the Chrome developer console also reveals the attribute to be present and correctly set to false.

Here is the code for my select in the form.

<%= f.select(:countries_id_eq, Country.order(:name).collect{|c| [c.name,c.id]}, {:prompt => "Exam Cycle"}, { :class => 'form-control input-lg', "data-dropup-auto" => "false" }) %>  

In the developer console, the select renders like this

<select class="form-control input-lg" id="q_universities_id_eq" name="q[universities_id_eq]" data-dropup-auto="false"><option value="">Subjects</option>...</select>  

Any help would be much appreciated.

App Server for Rails app deployment on Windows OS

Posted: 20 Jul 2016 06:48 AM PDT

I have been reading a few articles about alternative rack app servers since I'm facing performance issues with Thin server recently due to an increased number of users. Most of them recommend Passenger; but Windows OS is currently unsupported.

Deploying my rails app in Linux is not an option because it needs to interface with a file system on our Windows machine.

I'd just like to know what my options are now that I'm stuck on deploying on Windows OS.

  • Thin vs. Mongrel: it seems that Mongrel is not actively updated and Thin is better
  • Using Thin gives me performance issues. Since it looks like this is the best option for Windows OS, are there other configurations I can do?
  • Is it possible to run multiple Thin clusters in Windows?
  • Does using Apache/Nginx improve its performance?

Create action in controller test not working

Posted: 20 Jul 2016 06:19 AM PDT

Create action test in controller test not working properly and doesn't give info what's the problem.

 FAIL["test_should_create_invoice", InvoicesControllerTest, 2016-07-20 14:18:44 +0200]   test_should_create_invoice#InvoicesControllerTest (1469017124.50s)          "Invoice.count" didn't change by 1.          Expected: 2            Actual: 1          test/controllers/invoices_controller_test.rb:20:in `block in <class:InvoicesControllerTest>'  

Object parameters are from actual post request which worked fine. I've only changed client_id and seller_id params to get them from fixtures. Is it possible to check why this post request is not working in test environment?

invoices_controller_test.rb

  test "should create invoice" do      assert_difference('Invoice.count') do        post :create, invoice: {            date: "2016-07-07",            invoice_name_attributes: {              "number"=>"9",              "month"=>"7",              "year"=>"2016"            },            place: "Szczecin",            seller_id: clients(:client_google).id,            client_id: clients(:client_microsoft).id,            client_name: "Nazwa",            client_street: "Ulica",            client_zip: "23-232",            client_city: "Miasto",            client_country: "Polska",            client_email: "test@example.pl",            client_phone: "732-320-322",            invoice_items_attributes:            {              "0" => {                item_id: "2",                quantity: "1",                unit_price: "1.30",                tax_rate: "23",                net_price: "1.30",                value_added_tax: "0.30",                total_selling_price: "1.60",                _destroy: "false"              }            },            net_price: "1.30",            value_added_tax: "0.30",            total_selling_price: "1.60",            total_price_in_words: "jeden euro 60/100",            currency_rate_table_name: "129/A/NBP/2016",            currency_rate_name: "EUR",            currency_rate: "4.4469"          }      end        assert_redirected_to invoice_path(assigns(:invoice))    end  

This post request is working properly in dev and production environtemtn

Started POST "/invoices" for 127.0.0.1 at 2016-07-20 14:37:09 +0200  Processing by InvoicesController#create as HTML    Parameters: {"utf8"=>"✓", "authenticity_token"=>"tgTMZS15vBKkzadPrjgIatcxoi5CgFU79St5UYDDbyo=", "invoice"=>{"date"=>"2016-07-20", "invoice_name  _attributes"=>{"number"=>"3", "month"=>"7", "year"=>"2016"}, "place"=>"Warszawa", "seller_id"=>"2", "client_id"=>"1", "client_name"=>"Karol", "cl  ient_street"=>"Cicha", "client_zip"=>"71-100", "client_city"=>"Warszawa", "client_country"=>"Polska", "client_email"=>"test@gmail.c  om", "client_phone"=>"", "invoice_items_attributes"=>{"0"=>{"item_id"=>"2", "quantity"=>"1", "unit_price"=>"2", "tax_rate"=>"23", "net_price"=>"2  .00", "value_added_tax"=>"0.46", "total_selling_price"=>"2.46", "_destroy"=>"false"}}, "net_price"=>"2.00", "value_added_tax"=>"0.46", "total_selling_price"=>"2.46", "total_price_in_words"=>"dwa euro 46/100", "currency_rate_table_name"=>"138/A/NBP/2016", "currency_rate_name"=>"EUR", "curre  ncy_rate"=>"4.3811"}, "commit"=>"Create Invoice"}  

I am creating a chat room for friendship but message is viewed by all users . [duplicate]

Posted: 20 Jul 2016 05:35 AM PDT

In the channel

javascripts/channel/message.js

App.message = App.cable.subscriptions.create('MessageChannel', {     received: function(data) {        return $('#messages').append(this.renderMessage(data));    },    renderMessage: function(data) {      return "<p> <b>" + data.message + "</p>";    }  });  

Routes

  post 'messages/chat_create/:friendship_id/:friend_id' =>'messages#chat_create' , as:"chat_create"  

My Chatcontroller

class MessagesController < ApplicationController

def chat_create            @chat = current_user.messages.new(msg: params[:message][:msg],friend_id:params[:friend_id])              if @chat.save              ActionCable.server.broadcast 'message_channel',message: @chat.msg              redirect_to chat_path(params[:friendship_id])          end      end  

This is my view page

messages/chat.html.erb

<div id="messages">    <%=form_for :message, url: chat_create_path(params[:friendship_id],params[:friend_id]) , method: :post  do |f|%>  <%=f.text_field :msg %>  <%=f.submit%>  <%end%>    </div>  

I am trying to use this link https://github.com/rails/rails/tree/master/actioncable#channel-example-2-receiving-new-web-notifications but this is not working.

Rails: referencing independent entity

Posted: 20 Jul 2016 06:38 AM PDT

I have a Customer model that references a Location model. In the database table, customers table has a foreign key location_id to the locations table.

The relationship is unidirectional. What I mean is, Location is an independent entity and has no relation with Customer.

What I have is Customer.rb

:belongs_to :location  

and nothing in Location.rb.

What are the right associations to use for Customer and Location? How should I build the objects in new method?

The error I am getting now is -- Location(#70161843915060) expected, got ActionController::Parameters(#70161815174700)

UPDATE - 1

My form is for @customer and uses

f.fields_for :location  

Parameters go as -- Parameters: {"utf8"=>"✓", "authenticity_token"=>"Kz0iGeAA/pxWvZy3vORKshSdQSBndwlWiHiih8lKYqHsggL/sTBPlaukpVanyckdProZyI3zik2N07udpySvMA==", "customer"=>{"name"=>"MNC", "location"=>{"name"=>"HY"}

CSS acting jumpy when loading a page in Heroku

Posted: 20 Jul 2016 05:27 AM PDT

Every time I open a link in my rails app deployed on Heroku, it shows the visited page with absolutely no CSS before returning to normal view. Sometimes it acts jumpy and keeps changing between no-CSS and CSS view. This happens for like the first 1-2 seconds of visiting a link, and this happens for every link I visit within the app. Everything looks and works fine locally, though. Below are extracts from application.html.haml and application.css.scss in case they might be useful:

application.html.haml

%head    %title    %meta{:content => "IE=edge", "http-equiv" => "X-UA-Compatible"}/    = stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track' => true    = javascript_include_tag 'application', 'data-turbolinks-track' => true, 'data-turbolinks-eval': false    <link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet">    = csrf_meta_tags    %meta{:content => "width=device-width, initial-scale=1", :name => "viewport"}/   

application.css.scss

/*  *= require_self  *= require_tree .  *= require 'masonry/transitions'  *= require font-awesome  *= require jasny-bootstrap.min  */  // "bootstrap-sprockets" must be imported before "bootstrap" and "bootstrap/variables"  @import "bootstrap-sprockets";  @import "bootstrap";  

no route match rails 5

Posted: 20 Jul 2016 06:35 AM PDT

am trying to add routes to my rails app but everytime i try to load the index page it returns no route match. my

product.rb

belongs_to :category  extend FriendlyId  friendly_id :name, use: [:slugged, :finders]   default_scope { where(active: true) }  end  

and here is my category.rb

has_many :products    extend FriendlyId   friendly_id :name, use: [:slugged, :finders]  

and my routes are setup like this

    resources :categories      get '/products/:category_id/:id/', to: 'products#show', as: 'product'      resources :products  

in my index page i have it like this

<%= link_to product, class: "card" do %>  <div class="product-image">  <%= image_tag product.productpic.url if product.productpic? %>      </div>          <div class="product-text">          <h2 class="product-title"> <%= product.name %></h2>            <h3 class="product-price">£<%= product.price %></h3>        </div>            <% end %>      <% end %>  

but when ever i load the page in my broser i get

No route matches {:action=>"show", :category_id=>#<Product id: 4, name: "virgin hair", price: #<BigDecimal:7fd0af3ffb10,'0.3E3',9(18)>, created_at: "2016-07-19 12:34:34", updated_at: "2016-07-19 12:41:36", slug: "virgin-hair", productpic: "longhair.jpg", pdescription: "this a brazilian virgin hair", active: true, category_id: 2>, :controller=>"products"} missing required keys: [:id]  

what am i doing wrong here as i am a novice

Pass values from multiple checkboxes to button which when clicked iterates through method

Posted: 20 Jul 2016 04:56 AM PDT

I have a button which when clicked calls a path method e.g./operator/campaigns/new?campaign_id=

The code initially was designed so that each row had one of these buttons. I am attempting to change this so for every row there is a checkbox and when the checkbox is clicked the value associated with the row is passed to the button. If the user where to tick a few checkboxes it would be my intention that multiple values are passed to the method which then runs through each id.

Can anyone provide some indication how I could achieve this. The two mains problems I see are:

  1. Passing of the value. I could achieve this via jquery however I would prefer to implement it using ruby if possible.
  2. Running through the method x amount of times corresponding to x amount of checkboxes ticked.

My code is as below:

VIEW    .block-body    %table.table.table-striped.sla      %thead        %tr.medium          %th Campaign          %th Status          %th Approve          %th Reject      %tbody        - if @campaigns == nil          = @campaigns.inspect        - else          - @campaigns.each do |campaign|            %tr.medium              %td= link_to campaign.name              %td= campaign.status              %td= check_box_tag 'campaigns[]', new_operator_applied_campaign_path(:campaign_id => campaign), false              %td= check_box_tag 'campaigns[]', reject_operator_campaign_path(campaign), false        %tr.medium          %td{:colspan => 2}          %td            %span.input-group-btn              %button.btn.btn-success#approvedservicesbutton{:type => "submit", "data-toggle" => "tooltip", title: "Approve"}                = link_to new_operator_applied_campaign_path(:campaign_id => "campaign")           %td            %span.input-group-btn              %button.btn.btn-danger#rejectedservicesbutton{:type => "submit", "data-toggle" => "tooltip", title: "Reject"}      #reject-modal.modal.fade{"aria-hidden" => "true", "aria-labelledby" => "myModalLabel", role: "dialog", tabindex: "-1"}    .modal-dialog      .modal-content        = form_tag '#', method: :put do          .modal-header            %button.close{"aria-hidden" => "true", "data-dismiss" => "modal", type: "button"} ×            %h4#myModalLabel.modal-title Reject Aggregator          .modal-body            = text_area_tag :notes, nil, placeholder: 'Notes', class: 'form-control', :required=>true, rows: 5          .modal-footer            %button.btn.btn-default{"data-dismiss" => "modal", type: "button"} Close            %button.btn.btn-danger#submit-reject-btn{type: "submit"} Reject    :javascript    $('#reject-modal').on('show.bs.modal', function (e) {      $this = $(this);      $button = $(e.relatedTarget);      $this.find('.modal-title').html('Reject ' + $button.attr('campaign_name'));      $this.find('form').attr('action', $button.attr('reject_url'));    });      $('#reject-modal form').on('submit', function(){      $('#submit-reject-btn').attr('disabled', 'disabled').html('Submitting..');    });    CONTROLLER      def reject    authorize! :operator, current_user.operator    @campaign.data.merge!({:notes=>params[:notes]})    @campaign.status = "Rejected"    @campaign.save(validate: false)    redirect_to operator_campaigns_path, flash: { error: "#{@campaign.name} rejected."}  end  

rails 5.0.0 when installing "nio4r" : Failed to build gem native extension

Posted: 20 Jul 2016 04:58 AM PDT

Here is the logs: http://pastebin.com/CAgur9xd

Installing nio4r 1.2.1 with native extensions    Gem::Ext::BuildError: ERROR: Failed to build gem native extension.        C:/RailsInstaller/Ruby2.2.0/bin/ruby.exe -r ./siteconf20160720-8272-c88sgk.rb extconf.rb --with-cflags=-std=c99  checking for unistd.h... *** extconf.rb failed ***  Could not create Makefile due to some reason, probably lack of necessary  libraries and/or headers.  Check the mkmf.log file for more details.  You may  need configuration options.    Provided configuration options:          --with-opt-dir          --without-opt-dir          --with-opt-include          --without-opt-include=${opt-dir}/include          --with-opt-lib          --without-opt-lib=${opt-dir}/lib          --with-make-prog          --without-make-prog          --srcdir=.          --curdir          --ruby=C:/RailsInstaller/Ruby2.2.0/bin/$(RUBY_BASE_NAME)  C:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/mkmf.rb:456:in `try_do': The compiler failed to generate an executable file. (RuntimeError)  You have to install development tools first.          from C:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/mkmf.rb:587:in `try_cpp'           from C:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/mkmf.rb:1060:in `block in have_header'          from C:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/mkmf.rb:911:in `block in checking_for'          from C:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/mkmf.rb:351:in `block (2 levels) in postpone'          from C:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/mkmf.rb:321:in `open'          from C:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/mkmf.rb:351:in `block in postpone'          from C:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/mkmf.rb:321:in `open'          from C:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/mkmf.rb:347:in `postpone'          from C:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/mkmf.rb:910:in `checking_for'          from C:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/mkmf.rb:1059:in `have_header'          from extconf.rb:3:in `<main>'    extconf failed, exit code 1  

when installing bundle it returns(starts at line 117 in the logs ):

Installing nio4r 1.2.1 with native extensions  Gem::Ext::BuildError: ERROR: Failed to build gem native extension.  

So the bundle can't be installed. It returns at the end :

An error occurred while installing nio4r (1.2.1), and Bundler cannot continue.  Make sure that `gem install nio4r -v '1.2.1'` succeeds before bundling.  

Note :I have tried the solutions in other questions, but it is still the same. If it is possible to install "nio4r" manually please tell me how .

libsndfile.so.1: cannot open shared object file: No such file or directory

Posted: 20 Jul 2016 06:56 AM PDT

libsndfile.so.1: cannot open shared object file: No such file or directory - /opt/rubies/ruby-2.1.2/lib/ruby/gems/2.1.0/extensions/x86_64-linux/2.1.0-static/ruby-audio-1.6.1/rubyaudio_ext.so (LoadError)    /opt/rubies/ruby-2.1.2/lib/ruby/gems/2.1.0/gems/ruby-audio-1.6.1/lib/ruby-audio.rb:6:in `require'    /opt/rubies/ruby-2.1.2/lib/ruby/gems/2.1.0/gems/ruby-audio-1.6.1/lib/ruby-audio.rb:6:in `rescue in <top (required)>'    /opt/rubies/ruby-2.1.2/lib/ruby/gems/2.1.0/gems/ruby-audio-1.6.1/lib/ruby-audio.rb:1:in `<top (required)>'    /opt/rubies/ruby-2.1.2/lib/ruby/gems/2.1.0/gems/json-waveform-0.2.1/lib/json-waveform.rb:3:in `require'    /opt/rubies/ruby-2.1.2/lib/ruby/gems/2.1.0/gems/json-waveform-0.2.1/lib/json-waveform.rb:3:in `<top (required)>'    /opt/rubies/ruby-2.1.2/lib/ruby/gems/2.1.0/gems/bundler-1.6.2/lib/bundler/runtime.rb:76:in `require'    /opt/rubies/ruby-2.1.2/lib/ruby/gems/2.1.0/gems/bundler-1.6.2/lib/bundler/runtime.rb:76:in `block (2 levels) in require'    /opt/rubies/ruby-2.1.2/lib/ruby/gems/2.1.0/gems/bundler-1.6.2/lib/bundler/runtime.rb:72:in `each'    /opt/rubies/ruby-2.1.2/lib/ruby/gems/2.1.0/gems/bundler-1.6.2/lib/bundler/runtime.rb:72:in `block in require'    /opt/rubies/ruby-2.1.2/lib/ruby/gems/2.1.0/gems/bundler-1.6.2/lib/bundler/runtime.rb:61:in `each'    /opt/rubies/ruby-2.1.2/lib/ruby/gems/2.1.0/gems/bundler-1.6.2/lib/bundler/runtime.rb:61:in `require'    /opt/rubies/ruby-2.1.2/lib/ruby/gems/2.1.0/gems/bundler-1.6.2/lib/bundler.rb:132:in `require'    /var/app/current/config/application.rb:7:in `<top (required)>'    /var/app/current/config/environment.rb:2:in `require'    /var/app/current/config/environment.rb:2:in `<top (required)>'    config.ru:3:in `require'    config.ru:3:in `block in <main>  

But when i check as

"ll  /opt/rubies/ruby-2.1.2/lib/ruby/gems/2.1.0/extensions/x86_64-linux/2.1.0-static/ruby-audio-1.6.1/"  

File is present there in redhat aws server.

How can I fix this issue ? Thanks

Shopify Oauth2 Error [on hold]

Posted: 20 Jul 2016 04:23 AM PDT

I'm developing an application using shopify_app gem and sometimes when a shop installs my application, it triggers "Oauth error invalid_request: The authorization code was not found or was already used"

Since all authentication is done by the gem, I've no idea what caused this error.

Any help regarding this issue will be much appreciated

Capybara feature specs only working if js: true

Posted: 20 Jul 2016 04:58 AM PDT

My test code in the spec/features/posts_spec.rb looks like this

require 'spec_helper'  feature 'Posts' do    scenario 'Editing of Micropost', js: true do       visit '/signin'       fill_in 'Email', with: 'user@example.com  ...  

The code works fine with js: true. However if I take out js: true, the test fails at the fill_in 'Email' and if I use save_and_open_page immediately prior to this line I see

Not Found: /signin  

My understanding is that I should not have to put the js: true unless I need to test a javascript function and the default rack_test driver should work. What is going wrong? My spec_helper file is as follows

ENV['RAILS_ENV'] ||= 'test'  require File.expand_path('../../config/environment', __FILE__)  require 'rspec/rails'  require 'capybara'  require 'capybara/rails'  require 'capybara/rspec'  require 'capybara-screenshot'  require 'capybara-screenshot/rspec'  require 'capybara/poltergeist'  require 'pp'  require Rails.root.join('app/services/dbg').to_s  require 'database_cleaner_support'  require 'shoulda_matchers_support'  require 'chris_matchers_support'  require 'chris_helpers_support'  Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }  Capybara.default_host = 'www.example.com'  RSpec.configure do |config|    Capybara.default_driver = :rack_test    Capybara.javascript_driver = :poltergeist    Capybara::Webkit.configure(&:block_unknown_urls)    Capybara::Screenshot.prune_strategy = { keep: 20 }    Capybara::Screenshot.append_timestamp = false    config.include Capybara::UserAgent::DSL    config.include Rails.application.routes.url_helpers    config.include ApplicationHelper    config.include AccountsHelper    config.mock_with :rspec    config.fixture_path = "#{::Rails.root}/spec/fixtures"    config.use_transactional_fixtures = false    config.filter_run focus: true    config.run_all_when_everything_filtered = true    ActiveRecord::Migration.maintain_test_schema! # dont need db:test:prepare  end  RSpec.configure do |config|    config.before(:suite) do      DatabaseCleaner.clean_with(:truncation)    end    config.before(:suite) do      DatabaseCleaner.strategy = :transaction    end    # config.before(:each, :js => true) do    #     DatabaseCleaner.strategy = :truncation    # end    config.before(:each) do |example|      if example.example.metadata[:js]        DatabaseCleaner.strategy = :truncation      else        DatabaseCleaner.strategy = :transaction      end      DatabaseCleaner.start    end    config.after(:each) do      DatabaseCleaner.clean    end  end  

DataTables that have numbers followed by the percentage sign don't sort in order

Posted: 20 Jul 2016 03:53 AM PDT

I have a rails 4.2 app with datatables installed from the jquery datatables gem. It all works fine but when the data has numbers followed by a percentage character it doesn't sort the column in the correct order. e.g.

rows with numbers of 11%, 9%, and 25% will sort as 11%, 25%, 9% instead of 25%, 11%, 9% as highest to lowest (take away the % character and they sort correctly).

I have found this post on datatables but it says version 1.10+ should sort fine with percentages. That makes me think the gem uses a lower version. But they refer to version 1.10+ on the github page as if they are using a higher version than it.

Is the gem using a lower version than 1.10 or do I need to add some sort of tag to have percentage sorting work? I cant make sense of whats happening or what I need to do to make the sorting with percentages work

How to replace button in another view with javascript? Remote: true for link_to of an action in has_many trrough assosiation

Posted: 20 Jul 2016 03:22 AM PDT

Sorry for the long title. I don't know how I got stuck this much.

I wanted to have a button (actually a link_to styled as a button) for FOLLOW / UNFOLLOW on remote. That's a Follow model where records are stored for Corporation and User (a User can follow a Corporation). The follow/unfollow links are on the Corporation show page.

<% if user_signed_in? %>    <% if Follow.where(corporation_id: @corporation.id, user_id: current_user.id).first.nil? %>      <%= link_to 'FOLLOW', {:controller => "follows", :action => "create", :user_id => current_user.id, :corporation_id => @corporation.id}, remote: true, :method => "post", class: "btns follow", id: "follow1" %>    <% elsif %>     <%= link_to 'UNFOLLOW', {:controller => "follows", :action => "destroy", :corporation_id => @corporation.id, :user_id => current_user.id }, remote: true, :method => "delete", class: "btns unfollow", id: "unfollow" %>    <% end %>  <% end %>  

These are the controller actions:

def create    @corporation_id = params[:corporation_id]    @follow = Follow.new(follow_params)    @follow.save    respond_to do |format|      format.js {render :file => "/corporations/create.js.erb" }    end  end    def destroy    @corporation_id = params[:corporation_id]    attending.destroy    #attending is a method where the follow is defined. This is ok.    respond_to do |format|      format.js {render :file => "/corporations/destroy.js.erb" }    end  end  

I'm rendering create.js.erb in corporations, since the change has to happen there. If I leave it as format.js, it'll search in the follows folder which is empty.

The create.js.erb look like this:

$("#unfollow").click(function(){    $("unfollow").replaceWith("<%= escape_javascript(render :partial => "corporations/profile/follow", :locals => {corporation_id: @corporation_id}) %>");  });  

Btw, I tried .html instead of replaceWith, but it's not that.

The destroy.js.erb is similar. And the _unfollow.html.erb partial is like this:

<% if !@corporation.nil? %>    <%= link_to 'UNFOLLOW', {:controller => "follows", :action => "destroy", :corporation_id => @corporation.id, :user_id => current_user.id }, :method => "delete", class: "btns unfollow", remote: true, id: "unfollow" %>  <% else %>    <%= Rails.logger.info("First here") %>    <%= Rails.logger.info(corporation_id) %>    <%= link_to 'UNFOLLOW', {:controller => "follows", :action => "destroy", :corporation_id => corporation_id.to_i, :user_id => current_user.id }, :method => "delete", class: "btns unfollow", remote: true, id: "unfollow" %>    <%= Rails.logger.info("Now here...") %>  <% end %>  

Without the first condition it just fires up an error the corporation_id (it's same with locales[:corporation_id]) is not defined and similar.

I have no idea what to try now... All the tutorials on the net are quite simple but the remote action is just one action in the controller where it needs to change, this has to go to another controller then back, then again to Follow... I'd really appreciate the help.

How can I force Rails to reload application.js?

Posted: 20 Jul 2016 03:35 AM PDT

I've made some change in application.js, but even after restarting rails, I still have the same error and the source code the error show is the old one, it's not been changed. How can I force Rails to reload application.js?

FATAL: Peer authentication failed for user - (PG::ConnectionBad)

Posted: 20 Jul 2016 05:17 AM PDT

Having a Strange Issue. Deploying a Rails 5 App.

With

config.eager_load = true #in production.rb  

When I try starting Unicorn with

bundle exec unicorn -D -c /home/deploy/apps/cgrates_web_production/shared/config/unicorn.rb -E production  

I get this error

FATAL:  Peer authentication failed for user "demo"  (PG::ConnectionBad)  #in unicorn.log  

If I set

config.eager_load = false #in production.rb  

everything works as expected.

Thank You

No comments:

Post a Comment