Tuesday, August 9, 2016

No permission to drop SQLite3 development database Rails 5.0 on windows | Fixed issues

No permission to drop SQLite3 development database Rails 5.0 on windows | Fixed issues


No permission to drop SQLite3 development database Rails 5.0 on windows

Posted: 09 Aug 2016 07:31 AM PDT

I am trying to reset my development Database for my Rails 5.0 project on Windows, but when I run (same as rake db:drop)

rails db:drop  

I get the following error:

Errno::EACCES Permission denied @ unlink_internal

I restarted my PC already to make sure that rails was not running in anyway

undefined method for nil class when rendering partial

Posted: 09 Aug 2016 07:20 AM PDT

I'm trying to run this code and it returns me

undefined method `image' for nil:NilClass

But the syntax and the code seems to be good.

index :

 - @recipes.each_slice(4) do |recipes|    .row      - recipes.each do |recipe|        .col-md-3           %h4.modal-title= recipe.title           .modal-body              = render :partial =>'show', :locals => {:recipe => @recipe}  

_show:

.main_content    #recipe_top.row      .col-md-4        = image_tag @recipe.image.url(:medium), class:"recipe_image"  

How to send canvas image to database on form submit in Rails

Posted: 09 Aug 2016 07:31 AM PDT

I'm creating an app in Rails where users are able to draw on an html5 canvas with JavaScript. With JavaScript, I've been able to convert the canvas to an image so the user can easily right click the canvas and save the image:

var img = new Image;      img.onload = function(){       ctx.drawImage(img,0,0);      };      img.src = window.mapImgUrl;  

However, the problem is that the canvas lives on a form. I want the image result to somehow get added to the database so I can show previous drawings on other views of the app. I set up CarrierWave and AWS for image uploads, but I can't figure out a way to reconfigure the settings to treat the canvas images as uploads on submitting the form. Is this something that will have to involve AJAX or base64? Or is there some way to make use of CarrierWave for this?

rake db:migrate rake aborted! StandardError: An error has occurred

Posted: 09 Aug 2016 07:06 AM PDT

Would be very grateful if someone could help at least to understand where the issue could be coming from.

I'm having problems with migration with the project I'm working on. I even started a brand new one but the issue is still assuring the same. Error messages appearing on attempts to do rake db:migrate (have tried both starting new project with the default database- sqlite3 and the optional- postgresql ), however, after generating a model (tried both with rails g scaffold Schedule name:name dep_date:datetime and just model - rails g model Schedule name:name dep_date:datetime ) migration stays down.

the migration itself is:

class CreateSchedules < ActiveRecord::Migration[5.0]    def change     create_table :schedules do |t|       t.name :name       t.datetime :dep_date       t.timestamps     end   end  end  

command: rake db:migrate:status

gives the following:

database: travel_t_challenge_development    Status Migration ID Migration Name    down 20160809121048 Create schedules  

commands:

rake db:migrate     rake RAILS_ENV=production db:migrate or    rake db:migrate:up VERSION=20160809121048 or    bundle exec rake db:migrate VERSION=20160809121048  

(or redo)

result in the same error:

== 20160809121048 CreateSchedules: migrating ==================================  -- create_table(:schedules)  rake aborted!  StandardError: An error has occurred, this and all later migrations canceled:    wrong number of arguments (1 for 0)  /Users/[username]/workspace/travel_t_challenge/db/migrate/20160809121048_create_schedules.rb:4:in block in change' /Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract/schema_statements.rb:277:increate_table'  /Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/migration.rb:845:in block in method_missing' /Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/migration.rb:814:inblock in say_with_time'  /Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/migration.rb:814:in say_with_time' /Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/migration.rb:834:inmethod_missing'  /Users/[username]/workspace/travel_t_challenge/db/migrate/20160809121048_create_schedules.rb:3:in change' /Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/migration.rb:788:inexec_migration'  /Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/migration.rb:772:in block (2 levels) in migrate' /Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/migration.rb:771:inblock in migrate'  /Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:398:in with_connection' /Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/migration.rb:770:inmigrate'  /Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/migration.rb:950:in migrate' /Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/migration.rb:1211:inblock in execute_migration_in_transaction'  /Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/migration.rb:1279:in block in ddl_transaction' /Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract/database_statements.rb:232:inblock in transaction'  /Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract/transaction.rb:189:in within_new_transaction' /Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract/database_statements.rb:232:intransaction'  /Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/transactions.rb:211:in transaction' /Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/migration.rb:1279:inddl_transaction'  /Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/migration.rb:1210:in execute_migration_in_transaction' /Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/migration.rb:1183:inblock in migrate_without_lock'  /Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/migration.rb:1182:in each' /Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/migration.rb:1182:inmigrate_without_lock'  /Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/migration.rb:1131:in block in migrate' /Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/migration.rb:1298:inwith_advisory_lock'  /Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/migration.rb:1131:in migrate' /Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/migration.rb:1005:inup'  /Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/migration.rb:989:in migrate' /Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/tasks/database_tasks.rb:161:inmigrate'  /Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/railties/databases.rake:58:in block (2 levels) in <top (required)>' /Users/[username]/.rvm/gems/ruby-2.2.2/gems/rake-11.2.2/exe/rake:27:in'  /Users/[username]/.rvm/gems/ruby-2.2.2/bin/ruby_executable_hooks:15:in eval' /Users/[username]/.rvm/gems/ruby-2.2.2/bin/ruby_executable_hooks:15:in'  ArgumentError: wrong number of arguments (1 for 0)  /Users/[username]/workspace/travel_t_challenge/db/migrate/20160809121048_create_schedules.rb:4:in block in change' /Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract/schema_statements.rb:277:increate_table'  /Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/migration.rb:845:in block in method_missing' /Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/migration.rb:814:inblock in say_with_time'  /Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/migration.rb:814:in say_with_time' /Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/migration.rb:834:inmethod_missing'  /Users/[username]/workspace/travel_t_challenge/db/migrate/20160809121048_create_schedules.rb:3:in change' /Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/migration.rb:788:inexec_migration'  /Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/migration.rb:772:in block (2 levels) in migrate' /Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/migration.rb:771:inblock in migrate'  /Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:398:in with_connection' /Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/migration.rb:770:inmigrate'  /Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/migration.rb:950:in migrate' /Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/migration.rb:1211:inblock in execute_migration_in_transaction'  /Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/migration.rb:1279:in block in ddl_transaction' /Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract/database_statements.rb:232:inblock in transaction'  /Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract/transaction.rb:189:in within_new_transaction' /Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract/database_statements.rb:232:intransaction'  /Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/transactions.rb:211:in transaction' /Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/migration.rb:1279:inddl_transaction'  /Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/migration.rb:1210:in execute_migration_in_transaction' /Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/migration.rb:1183:inblock in migrate_without_lock'  /Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/migration.rb:1182:in each' /Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/migration.rb:1182:inmigrate_without_lock'  /Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/migration.rb:1131:in block in migrate' /Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/migration.rb:1298:inwith_advisory_lock'  /Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/migration.rb:1131:in migrate' /Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/migration.rb:1005:inup'  /Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/migration.rb:989:in migrate' /Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/tasks/database_tasks.rb:161:inmigrate'  /Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/railties/databases.rake:58:in block (2 levels) in <top (required)>' /Users/[username]/.rvm/gems/ruby-2.2.2/gems/rake-11.2.2/exe/rake:27:in'  /Users/[username]/.rvm/gems/ruby-2.2.2/bin/ruby_executable_hooks:15:in eval' /Users/[username]/.rvm/gems/ruby-2.2.2/bin/ruby_executable_hooks:15:in'  Tasks: TOP => db:migrate  (See full trace by running task with --trace)  

Dropping and setting up/creating the database again hasn't helped either.

System configuration

Rails version:5.0.0 Ruby version:2.2.3

Rails gem Reform show errors

Posted: 09 Aug 2016 06:48 AM PDT

Tell me whether it is possible somehow to deduce errors in the classical Active Model style?

Example show error

my method:

def update      address = Address.find(@user.billing_address)      form = AddressForm.new(address)      if form.validate(params[:billing])        form.save      else        flash[:notice] = form.errors.full_masseges      end    end  

my form object:

class AddressForm < Reform::Form    include Reform::Form::ActiveModel::Validations    include Reform::Form::ActiveModel::FormBuilderMethods      property :first_name    property :last_name    property :address    property :city    property :country_id    property :zipcode    property :phone      extend ActiveModel::ModelValidations    copy_validations_from Address    end  

I would like to display error as top picture

Paperclip::Error (There was an error processing the thumbnail

Posted: 09 Aug 2016 06:58 AM PDT

Paperclip::Error in RegistrationsController#update There was an error processing the thumbnail.

I'm Running Rails 4.2.6

and paperclip", "~> 5.0.0"

My application controller file is:

class NewsController < ApplicationController   def create   @news = News.new(news_params)      respond_to do |format|     if @news.save       format.html { redirect_to news_url, notice: 'News post was successfully created.' }       format.json { render :show, status: :created, location: @news }     else       format.html { render :new }       format.json { render json: @news.errors, status: :unprocessable_entity }     end    end   end     private   def news_params     params.require(:news).permit(:topic, :header, :content, :link, :image)   end  end  

My news model is:

class News < ActiveRecord::Base      validates :image, presence: true        has_attached_file :image, styles: { thumb: "64x64#", small: "100x100#", med: "150x150#", large: "200x200# -adaptive-resize" }, default_url: "/images/:style/missing.png"      validates_attachment_content_type :image, :content_type => /\Aimage\/.*\Z/  end  

And my database migration for paperclip is:

class AddAttachmentImageToNews < ActiveRecord::Migration    def self.up      change_table :news do |t|        t.attachment :image      end    end      def self.down      remove_attachment :news, :image    end  end  

When I rake db:migrate this and then try to use it I get the Paperclip::Error in NewsController#create There was an error processing the thumbnail for dfc9ea4994791a9884f662cfa4333da420160809-29993-12b0k3n.

I previously had an attribute of the news class called image, not sure if that messes anything up?

It seems like it's a database problem, since if I do a rake db:setup it works fine. But, I don't want to wipe my database, so that's not an option, since db:setup runs a db:schema:load this will delete data on the server.

Any help or suggestions would be appreciated. Thanks.

How can I make a link to the result of a model method in my views?

Posted: 09 Aug 2016 06:47 AM PDT

I have this method in my model:

  ## Finds invoice with next upcoming due date. ##    def self.next_due      where("due_date >= ? AND status = ?", Time.now, 'Open').order("due_date ASC").first ? where("due_date >= ?", Time.now).order("due_date ASC").first.due_date : ''    end  

This returns the due_date of the next invoice due.

I am trying to make a link_to to the actual invoice but so far have not been able to get it to work.

I feel like such an idiot because I can't make a simple link work when I've had no problems with links that I couldn't quickly sort out on my own up till now.

Is it possible to store the invoice returned by this query as a variable that I can call from the view and link to? If not, then how would I go about making the link?

Thanks.

How to generate barcode fast

Posted: 09 Aug 2016 06:27 AM PDT

if File.directory?("#{Rails.root}/public/barcodes") == false    system 'mkdir', '-p', "#{Rails.root}/public/barcodes"  end    Parallel.each((1000000000001..1000000001000).to_a, in_processes: 10) do |barcode_number|    barcode = Barby::Code128B.new(barcode_number)    File.open("#{Rails.root}/public/barcodes/#{barcode_number}.png", 'wb'){ |f|      f.write barcode.to_png(height: 50, xdim: 2, margin: 2)    }      Barcode.create(member_id: barcode_number.to_s, barcode_image: File.open("#{Rails.root}/public/barcodes/#{barcode_number}.png"))  end    FileUtils.rm_f Dir.glob("#{Rails.root}/public/barcodes/*")  

Above is my code that generate barcode and store into AWS S3 server.

The functionality is working fine as per the my requirement. If I generate 1000 barcodes then it will take 60 to 70 Sec.

Now, I want to optimize the time, I want to store 1000 barcodes with in less then 20 sec. So How can I do this?

When using dotenv gem, the pages I wish to authenticate crash the app in heroku

Posted: 09 Aug 2016 06:15 AM PDT

I have added a scaffold to add bookings and post blogs on my application. However these need to be authenticated. I used the dotenv gem for this and now, although I have managed to push to heroku, the main functionality does not work. I have the config variables in the heroku dashboard. I'm fairly new to rails s. I'm struggling with how to get the app fully functioning on heroku. Thanks

My gem file looks like so:

gem 'dotenv-rails', '~> 2.1', '>= 2.1.1'    gem 'rails', '4.2.5'    gem 'pg'    gem 'sass-rails', '~> 5.0'    gem 'uglifier', '>= 1.3.0'    gem 'coffee-rails', '~> 4.1.0'    gem 'will_paginate', '~> 3.1.0'    gem 'jquery-rails'    gem 'turbolinks'    gem 'jbuilder', '~> 2.0'    gem 'sdoc', '~> 0.4.0', group: :doc    gem "font-awesome-rails"      gem 'will_paginate-bootstrap'    gem "paperclip", "~> 5.0.0"    gem 'rails_12factor', group: :production    group :development, :test do    # Call 'byebug' anywhere in the code to stop execution and get a debugger console    gem 'byebug'    end      group :development do      gem 'web-console', '~> 2.0'        gem 'spring'  end  

My Application.rb has this

require File.expand_path('../boot', __FILE__)    require 'rails/all'  require 'dotenv' ; Dotenv.load ".env.local", ".env.#{Rails.env}"    Bundler.require(*Rails.groups)    module Owen    class Application < Rails::Application        config.active_record.raise_in_transactional_callbacks = true    end  end  

The logs output by heroku looks like this:

2016-08-09T13:01:00.950755+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/railties-4.2.5/lib/rails/application.rb:165:in `call'  2016-08-09T13:01:00.950755+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/rack-1.6.4/lib/rack/lock.rb:17:in `call'  2016-08-09T13:01:00.950760+00:00 app[web.1]:   2016-08-09T13:01:00.950758+00:00 app[web.1]:   vendor/ruby-2.2.4/lib/ruby/2.2.0/webrick/httpserver.rb:94:in `run'  2016-08-09T13:01:00.950759+00:00 app[web.1]:   vendor/ruby-2.2.4/lib/ruby/2.2.0/webrick/server.rb:294:in `block in start_thread'  2016-08-09T13:01:00.904039+00:00 heroku[router]: at=info method=GET path="/assets/application-fbbd908cea354d615a36d08b266857a33539efedccec032961bf3f7e4b7fbd7e.css" host=mysterious-eyrie-34368.herokuapp.com request_id=607efaf0-bf7c-4b6e-a6aa-d5826431865d fwd="37.228.247.76" dyno=web.1 connect=1ms service=4ms status=304 bytes=133  2016-08-09T13:01:00.906216+00:00 heroku[router]: at=info method=GET path="/assets/application-b1affcac82903b220e62f8a83f67d4523e5d7193c77560b624c4d295bcf53182.js" host=mysterious-eyrie-34368.herokuapp.com request_id=89e148bb-d39b-45b3-a2e0-dd4e67ebea45 fwd="37.228.247.76" dyno=web.1 connect=1ms service=4ms status=304 bytes=133  

rails in ubuntu error of permission denied

Posted: 09 Aug 2016 06:22 AM PDT

hi i have installed ubuntu and and copied the old data which is done in windows. now i am getting error when i run bundle install...

I ran the command /usr/local/bin/bundle install

Error details

Errno::EACCES: Permission denied @ dir_s_mkdir - /home/gohub/.bundle/cache/compact_index/rubygems.org.80.9e8aca59a0c3a407fba89eb64623162d/versions20160809-21504-1s0noda    /usr/lib/ruby/2.3.0/tmpdir.rb:86:in `mkdir'    /usr/lib/ruby/2.3.0/tmpdir.rb:86:in `block in mktmpdir'    /usr/lib/ruby/2.3.0/tmpdir.rb:130:in `create'    /usr/lib/ruby/2.3.0/tmpdir.rb:86:in `mktmpdir'    /var/lib/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/vendor/compact_index_client/lib/compact_index_client/updater.rb:29:in `update'    /var/lib/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/vendor/compact_index_client/lib/compact_index_client.rb:64:in `update'    /var/lib/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/vendor/compact_index_client/lib/compact_index_client.rb:55:in `update_and_parse_checksums!'    /var/lib/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/fetcher/compact_index.rb:65:in `available?'    /var/lib/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/fetcher/compact_index.rb:15:in `call'    /var/lib/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/fetcher/compact_index.rb:15:in `block in compact_index_request'    /var/lib/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/fetcher.rb:154:in `use_api'    /var/lib/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/source/rubygems.rb:331:in `block in api_fetchers'    /var/lib/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/source/rubygems.rb:331:in `select'    /var/lib/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/source/rubygems.rb:331:in `api_fetchers'    /var/lib/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/source/rubygems.rb:336:in `block in remote_specs'    /var/lib/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/index.rb:10:in `build'    /var/lib/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/source/rubygems.rb:335:in `remote_specs'    /var/lib/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/source/rubygems.rb:82:in `specs'    /var/lib/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/lazy_specification.rb:56:in `__materialize__'    /var/lib/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/spec_set.rb:91:in `block in materialize'    /var/lib/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/spec_set.rb:88:in `map!'    /var/lib/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/spec_set.rb:88:in `materialize'    /var/lib/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/definition.rb:140:in `specs'    /var/lib/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/definition.rb:129:in `resolve_remotely!'    /var/lib/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/installer.rb:195:in `resolve_if_need'    /var/lib/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/installer.rb:70:in `run'    /var/lib/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/installer.rb:22:in `install'    /var/lib/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/cli/install.rb:102:in `run'    /var/lib/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/cli.rb:175:in `install'    /var/lib/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'    /var/lib/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command'    /var/lib/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/vendor/thor/lib/thor.rb:359:in `dispatch'    /var/lib/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/vendor/thor/lib/thor/base.rb:440:in `start'    /var/lib/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/cli.rb:11:in `start'    /var/lib/gems/2.3.0/gems/bundler-1.12.5/exe/bundle:27:in `block in <top (required)>'    /var/lib/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/friendly_errors.rb:98:in `with_friendly_errors'    /var/lib/gems/2.3.0/gems/bundler-1.12.5/exe/bundle:19:in `<top (required)>'    /usr/local/bin/bundle:22:in `load'    /usr/local/bin/bundle:22:in `<main>'  

Environment

Bundler   1.12.5  Rubygems  2.6.6  Ruby      2.3.1p112 (2016-04-26 revision 0) [x86_64-linux-gnu]  GEM_HOME  /var/lib/gems/2.3.0  GEM_PATH  /var/lib/gems/2.3.0:/home/gohub/.gem/ruby/2.3.0:/usr/lib/x86_64-linux-gnu/rubygems-integration/2.3.0:/usr/share/rubygems-integration/2.3.0:/usr/share/rubygems-integration/all  Git       2.7.4  

Bundler settings

orig_path    Set via BUNDLE_ORIG_PATH: "/home/gohub/bin:/home/gohub/.local/bin:/usr         /local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:         /bin:/usr/games:/usr/local/games:/snap/bin:/home/gohub         /.rvm/bin:/home/gohub/.rvm/bin"  

Unfortunately, an unexpected error occurred, and Bundler cannot continue.

First, try this link to see if there are any existing issue reports for this error/

If there aren't any reports for this error yet, please create copy and paste the report template above into a new issue. Don't forget to anonymize any private data! The new issue form is located here.

whole RUBY hashmap printed out after ".each" loop

Posted: 09 Aug 2016 06:24 AM PDT

I am iterating over a Hashmap of type . Works pretty well. My problem is, it prints out the whole Hashmap as String after the wanted output.

Screenshot

What is happening? How can i prevent my app from doing that?

Edit: sorry for being silly.. totally forgot that!

source-code:

<div style="display: inline-block">     <%= @tag_color_hash.each do |tag, color| %>         <%= f.label tag, :style => "border-color: #{color}", :class => 'tags'%>     <% end %>  </div>  

How to display posts using Modals

Posted: 09 Aug 2016 06:13 AM PDT

I'm new to RoR and I've encountered a problem recently as I am trying to display different posts in different modals. To contextualize I have a Home page on which is displayed every post. Every post contains an author, a content, a like button and a comment button. I want the comment button to open a modal containing again the author's name, the content and an area to comment the post. The problem is that every modal that I click on contains the same author and the same content even if the comment button I clicked on is from a different post. To be precise the content displayed in the Modal is from the most recently posted post. Tell me if you need something in particular and I will be happy to edit this post with the code you ask me.

Displaying the posts:

<% @posts.each do |post| %>             <div class="media">      <a class="media-left" href="#">        <div class='circle-icon'>          <span class="glyphicon glyphicon-user" aria-hidden="true"></span>        </div>      </a>      <div class="media-body">        <h2 class="media-heading"><%= post.user.first_name %> <%= post.user.last_name %></h2>        <h4><%= post.content %> </h4>        <br>Submitted <%= time_ago_in_words (post.created_at) %> ago<br>        <%= button_to like_post_path(post), method: :put do %>Like<%= post.get_upvotes.size %>  <% end %>  <a  href="#" data-toggle="modal" data-target="#myModal" class="btn btn-xs btn-primary"><span class="glyphicon glyphicon-comment"></span> Comment</a>  

And here is my Modal:

<!-- Modal -->    <div class="modal fade .local-modal" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">    <div class="modal-dialog" role="document">      <div class="modal-content">        <div class="modal-header">          <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>          <h4 class="modal-title" id="myModalLabel"><%= post.user.first_name %> <%= post.user.last_name %></h4>        </div>        <div class="modal-body">          <p><%= post.content %> </p>          <hr>          <fieldset class="form-group">            <label for="exampleTextarea">Write your comment:</label>            <textarea class="form-control" id="exampleTextarea" rows="3">   </textarea>          </fieldset>        </div>        <div class="modal-footer">          <button type="button" class="btn btn-default" >Like</button>          <button type="button" class="btn btn-primary" data-dismiss="modal">Comment</button>        </div>      </div>    </div>   </div>               

Rspec Mocking A Class Instance

Posted: 09 Aug 2016 05:55 AM PDT

If in my Rspec test I have...

foo = mock_model(Foo, id: 1)  

& my code runs...

Foo.where(id: 1)  

My code will always fail as the mock_model foo never gets to belong to the Foo collection...

e.g. Foo.count # => 0

If I run foo.instance_of?(Foo) i'll get true so the behaviours right... What am I missing? I'd like to rely on true mocks & not have to rely on FactoryGirl or instantiate an object of Foo itself...

filterrific with many_to_many assotiations that depends on 2 tables

Posted: 09 Aug 2016 05:54 AM PDT

I have table Products that associates with Options table through ProductOptions. Options table has 'name' column and ProductOptions table has 'value' column. I need to filter Products by Option name column with ProductOptin value column. ex.: Option.name = 'gender', ProductOption.value = 'Mens' => list of products... I found the filterrific gem is a good solution for this, but I can't make a right scope. I'll be glad for any help..

How to save city, state, zip and country based on address using geocoder gem

Posted: 09 Aug 2016 05:43 AM PDT

I have user model in which user search address and what I need to do is to update fields like city, state, zip and country based on that address.

The problem I am facing is, I cant able to get this information and pass it to update params.

See code:

geocoded_by :address  do |obj,results|      if geo = results.first        obj.city    = geo.city        obj.lat = geo.latitude        obj.lng = geo.longitude        obj.zip = geo.postal_code        obj.state = geo.state        obj.country = geo.country_code      end    end    after_validation :address  

If I puts results and geo it returns nil only. I wants to have Longitude, Latitude, city, state, zip, and country based on Address search and then pass all of them to update method so they will automatically get updates in the system.

And for doing all of this I am using Geo Coder GEM

How to edit the records of more than one table in rails based on relationship and nested attributes?

Posted: 09 Aug 2016 05:43 AM PDT

Here i have save my user,load,load_lead table data with referenced to company_id. But i don't know how to edit my data from various tables.How can i resolve this error?There are four tables named as(company,user,load,load_lead).

Load Acquisition

<%= form_for :load_acquisitions, :url=>{:controller=>"load_acquisitions",:action=>"update"} do|ff|%>    <%lq=@load_acquisitions[0].id%>    <%Company.where(:id=>lq).each do|f|%>    <div class="field">      <%= f.label :load_pick_from_date %>      <%= f.text_field :load_pick_from_date %>    </div>      <div class="field">      <%= f.label :load_pick_to_date %>      <%= f.text_field :load_pick_to_date %>    </div>      <div class="field">      <%= f.label :source_id %>      <%= f.text_field :source_id %>    </div>      <div class="field">      <%= f.label :destination_id %>      <%= f.text_field :destination_id %>    </div>      <div class="field">    <%= f.label :truck_type_id%>    <%= f.text_field :truck_type_id%>    </div>      <div class="field">  <%= f.label :load_type_id %>  <%= f.text_field :load_type_id %>  </div>    <div class="field">  <%= f.label :city_id %>  <%= f.text_field :city_id %>  </div>    <div class="field">  <%= f.label :company_identification_number %>  <%= f.number_field :company_identification_number %>  </div>      <div class="field">      <%= f.label :negotiated_price %>      <%= f.text_field :negotiated_price %>     </div-->     <div class="field">      <%= f.label :company_name %>      <%= f.text_field :company_name %>    </div>     <div class="field">      <%= f.label :email %>      <%= f.email_field :email %>    </div>      <div class="field">      <%= f.label :mobile_number %>      <%= f.number_field :mobile_number %>    </div>      <div class="field">      <%= f.label :landline_number %>      <%= f.telephone_field :landline_number %>    </div>      <div class="field">      <%= f.label :name %>      <%= f.text_field :name %>    </div>      <div class="field">      <%= f.label :notes  %>      <%= f.text_field :notes %>    </div>  <%=f.submit "save"%>  <%end%>  <%end%>  

My controller def edit @load_acquisitions=Company.where(:id=>params[:id]).includes([:users,:loads,:load_leads]) end

  def update     @load_acquisitions=LoadAcquisition.update(load_acquisition_params)          if @load_acquisitions.update        @load_acquisitions.load_acqu_generate       redirect_to root_url, notice: "Success!"      else       render "new"      end    end  

I want to show all data from various tables into my edit page with edit mode.How to do that? company(name,company_identi_no,city_id) User(name,email,mob_no,lan_no) Load(load_pic_from_date,load_pic_to_date,source,destination,load_type,notes,nego_price) load_lead(truck_type)

Rails 5 belongs_to_required_by_default does't work

Posted: 09 Aug 2016 06:55 AM PDT

I use Rails 5.0.0, but for some reason belongs_to_required_by_default doesn't work!

Application was created as new rails 5 app

class Visit < ApplicationRecord    belongs_to :user  end    > v = Visit.new  > v.valid? # => true  

it works only with optional: false option

class Visit < ApplicationRecord    belongs_to :user, optional: false  end    > v = Visit.new  > v.valid? # => false  

but why doesn't work configuration:

Rails.application.config.active_record.belongs_to_required_by_default = true  

Thanks for any suggestions

Decrypt field values encrypted using attr_encrypted before exporting model data to csv file (Rails 4)

Posted: 09 Aug 2016 05:21 AM PDT

I use gem attr_encrypted to encrypt and decrypt attributes and I have a module to export model data as a csv file. I want to deccrypt the encrpted field data before exporting to csv

module to export model data as a csv file.

#app/models/concerns/csv_exportable.rb  module CsvExportable    extend ActiveSupport::Concern    included do      def self.to_csv(options = {})        CSV.generate(options) do |csv|          csv << column_names          all.each do |record|            csv << record.attributes.values_at(*column_names)          end        end      end    end  end  

I then include the module in models across my app like

class Product < ActiveRecord::Base      include CsvExportable        .        .  end  

I wonder how to check each field is encrypted or not before pushing to csv, and if encrypted decrypt the same

Ruby on rails - Datepicker with I18n - Jquery

Posted: 09 Aug 2016 05:16 AM PDT

I am changing my current datepicker to this, daterangepicker.

I have this working correctly but I am having trouble with the translations. I think it's a jquery problem as if I put in a comma after the last translation, the calendar shows in Spanish regardless or locale, and if I leave out this comma then the calendar shows in English, regardless of locale.


datepicker jquery:

$(function() {    return $('#q_daterange').daterangepicker({        "autoApply": true,        "locale": {            "format": "MM/DD/YYYY",            "daysOfWeek": ['<%= I18n.t('datepicker.sun') %>',                               '<%= I18n.t('datepicker.mon') %>',                               '<%= I18n.t('datepicker.tue') %>',                               '<%= I18n.t('datepicker.wed') %>',                               '<%= I18n.t('datepicker.thu') %>',                               '<%= I18n.t('datepicker.fri') %>',                               '<%= I18n.t('datepicker.sat') %>'                               ],            "monthNames": [                             '<%= I18n.t('datepicker.january') %>',                             '<%= I18n.t('datepicker.february') %>',                             '<%= I18n.t('datepicker.march') %>',                             '<%= I18n.t('datepicker.april') %>',                             '<%= I18n.t('datepicker.may') %>',                             '<%= I18n.t('datepicker.june') %>',                             '<%= I18n.t('datepicker.july') %>',                             '<%= I18n.t('datepicker.august') %>',                             '<%= I18n.t('datepicker.september') %>',                             '<%= I18n.t('datepicker.october') %>',                             '<%= I18n.t('datepicker.november') %>',                             '<%= I18n.t('datepicker.december') %>'            ],            "firstDay": 1        },        "showCustomRangeLabel": false,         "minDate": new Date(),        "startDate": new Date(),        "endDate": new Date(+new Date + 12096e5),        "opens": "left",    }, function(start, end, label) {      $('#q_date_gteq').val(start.format("YYYY-MM-DD"));      return $('#q_date_lteq').val(end.format("YYYY-MM-DD"));    }).on('apply.daterangepicker', function() {      return $('#gig_search').submit();    });  });  

Note the line '<%= I18n.t('datepicker.december') %>' has no comma after it. Everything currently shows in English. Adding a comma here makes everything show in Spanish.

I cannot spot my error, any help would be appreciated!!

Can I store data in js session and retrieve it in Ruby on rails?

Posted: 09 Aug 2016 05:08 AM PDT

I need to save data to session or cookies in javascript, and after form submitting retrieve these data in active admin.

Sidekiq With Whenever

Posted: 09 Aug 2016 04:29 AM PDT

I'm using whenever for schedule of job with sidekiq. Also, use sidekiq-client-cli gem, that is a command line client for sidekiq and allows the cron jobs to interact with sidekiq.

This my active job file :

# jobs/clone_record_job.rb    class CloneRecordJob < ActiveJob::Base      queue_as :myapps        def perform(*args)        Core::Block.where(release_date: Date.today - 30.days).each do |block|          new_block = Core::Block.new(block.attributes)          new_block._id = BSON::ObjectId.new          new_block.save        end      end  end  

schedule file :

# config/schedule.rb  job_type :sidekiq, "cd :path && :environment_variable=:environment bundle exec sidekiq-client -q myapps push :task :output"    every 1.minute, :roles => [:app] do      sidekiq "CloneRecordJob"  end  

Sidekiq log :

2016-08-09T10:13:41.138Z 23668 TID-xvshg WARN: {"class":"CloneRecordJob","queue":"myapps","args":[],"retry":true,"jid":"98cb26a0dd7410a9be0f0200","created_at":1470737621.1380692,"enqueued_at":1470737621.1382036}  2016-08-09T10:13:41.141Z 23668 TID-xvshg WARN: NoMethodError: undefined method `jid=' for #<CloneRecordJob:0x0000000715cc30>  

Note :

I'm sure that job is work when to call from controller.

# example method  def my_action    CloneScheduleJob.perform_now  end  

Linking to Users Profile Rails

Posted: 09 Aug 2016 04:37 AM PDT

I'm creating a profile for registered users using devise, and once they register it automatically creates a profile, My problem is, Inside the dashboard, I want to link to their profile and unsure what parameters I need to pass into the path to satisfy the id paramter?

User Model:

class User     has_one :student_profile, dependent: :destroy  end  

Profile Model :

class StudentProfile < ActiveRecord::Base      belongs_to :user      validates_associated :user        def completed_profile?          self.first_name.present? && self.last_name.present?      end    end  

I am using scaffold generated code for the controllers and untouched?

Inside my View Html.erb file I wanted to use the logged in users profile to be passed in so they can view or edit it.

 <%= link_to "View Profile", student_profile_path(@student_profile), :class => 'btn btn-primary' %>   

However it is displaying the error missing [:id], Which I understand, but I am unsure what to pass into the "Student_profile_path()" link.

Do I need to update the show method in the profile controller?

Any help appreciated.

How to resize image before deploying to S3 through s3_direct_upload gem rails

Posted: 09 Aug 2016 04:20 AM PDT

After attaching file i want to resize image to 50*50 and then want to upload to S3. I am using s3_direct_upload , i have read the documentation there i found max_file_size which is good but i want user to upload any size of image and then resize into my fixed size and then upload to S3. Can anyone have idea how to accomplish it through S3 direct upload gem.

Rails Advanced Associations

Posted: 09 Aug 2016 04:49 AM PDT

I got three models called User, Account and AccountPermission.

I established associations between User and Account through AccountPermission so, It's has_many :through

I also established User and Account with has_many via creator_id. Because, I need to know the creator of accounts.

I'm creating Account and User same time with nested attributes. However, I also want to add a creator_id to my User in same transaction.

Do you have any idea for this case ?

Here is my associations,

associations

user.rb

class User < ActiveRecord::Base         has_many :created, class_name: 'Account', :foreign_key => 'creator_id'         has_many :account_permissions, :class_name => 'AccountPermission'       has_many :accounts, through: :account_permissions         accepts_nested_attributes_for :account_permissions  

account.rb

class Account < ActiveRecord::Base        belongs_to :creator, class_name: 'User'        has_many :accounts_permissions, :class_name => 'AccountPermission'      has_many :users, through: :accounts_permissions  

account_permission.rb

class AccountPermission < ApplicationRecord      belongs_to :user      belongs_to :account        accepts_nested_attributes_for :account  

controller#new

 def new      @user = User.new      @user.account_permissions.build.build_account      respond_with(@user)   end  

My SQL,

  (0.3ms)  BEGIN    SQL (12.4ms)  INSERT INTO "users" ("email", "encrypted_password", "first_name", "last_name", "created_at", "updated_at", "country") VALUES ($1, $2, $3, $4, $5, $6, $7) RETURNING "id"  [["email", "testemail@gmail.com"], ["encrypted_password", "$2a$11$2XeCSewQ3JqIFNjwktfQZ.nt/.iWsT7ea6SSmVrrzWAcqHqMuubUy"], ["first_name", "test name"], ["last_name", "test lastname"], ["created_at", 2016-08-09 11:15:46 UTC], ["updated_at", 2016-08-09 11:15:46 UTC], ["country", "EC"]]        SQL (4.4ms)  INSERT INTO "accounts" ("name", "created_at", "updated_at") VALUES ($1, $2, $3) RETURNING "id"  [["name", "testsubdomain"], ["created_at", 2016-08-09 11:15:46 UTC], ["updated_at", 2016-08-09 11:15:46 UTC]]        SQL (6.4ms)  INSERT INTO "account_permissions" ("user_id", "account_id", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "id"  [["user_id", 51], ["account_id", 19], ["created_at", 2016-08-09 11:15:46 UTC], ["updated_at", 2016-08-09 11:15:46 UTC]]        (1.9ms)  COMMIT    (0.2ms)  BEGIN  

Ruby on Rails Session Variable not Showing on Front End on First Render

Posted: 09 Aug 2016 04:19 AM PDT

I'm having a strange issue where the last value in a session array is not displaying on the front end when a partial is rendered for the first time. I'm using the add_to_box method to add a set of values to a session variable called 'session[:box]'. I then want to update the partial on the front end with the new list of values.

Here's the code... (sanitised slightly)

Controller:

def add_to_box(values_hash)      session[:box] ||= []    if params_valid?(values_hash)        session[:box].push(values_hash)        respond_to do |format|        format.js      end      end    end  

add_to_box.js.erb:

$("#box").html("<%= escape_javascript(render partial: 'box') %>");  

Partial _box.html.erb:

<ul>    <% session[:box].each do |m| %>      <li>        <%= "#{m['bottom_id']}, #{m['filling_id']}, #{m['top_id']}" %>      </li>    <% end %>  </ul>  

Console output:

Started POST "/things/add_to_box" for ::1 at 2016-08-09 11:59:23 +0100  Processing by ThingController#add_to_box as JS  Rendered things/_box.html.erb (0.9ms)  Rendered things/add_to_box.js.erb (2.8ms)  Completed 200 OK in 17ms (Views: 8.2ms | ActiveRecord: 0.7ms)  

The first time the method is called (values 1,1,1), the front end displays as:

∙ , ,

The second time the method is called (values 2,2,2), the front end displays as:

∙ 1, 1, 1

∙ , ,

The third time the method is called (values 3,3,3), the front end displays as:

∙ 1, 1, 1

∙ 2, 2, 2

∙ , ,

You get the picture... Essentially the latest value is never rendered.

BUT if I refresh the page, it shows correctly with all values:

∙ 1, 1, 1

∙ 2, 2, 2

∙ 3, 3, 3

I thought at first it could be because the values aren't saved in time and the render is happening first, but then how does it know there is a new set of values before they have been set?!

Need some help on this one

Building an RSVP system in Rails with has_many, through

Posted: 09 Aug 2016 04:25 AM PDT

I have an Events app in Rails 5 and I'm trying to build an RSVP system.

The functionality that I'm trying to build is that a user can go to the events show page and click an 'rsvp' button. This user will then show up in the events show page under 'users attending this event'. Additionally, the event will also show up on the user's show page - 'this user is attending the following events'.

I'm pretty new to Rails and I'm not really sure how to handle the rsvp button functionality. This is my code so far:

user.rb

class User < ApplicationRecord  ...    has_many :attendances    has_many :events, through: :attendances  ...  end  

event.rb

class Event < ApplicationRecord      has_many :attendances    has_many :users, through: :attendances    end  

attendance.rb

class Attendance < ApplicationRecord    belongs_to :user    belongs_to :event  end  

routes.rb

Rails.application.routes.draw do    root 'events#index'      resources :events do      resources :users    end      resources :users        end  

And this is the form on the events show page where I'm trying to add a user to the event

show.html.erb - events

<%= form_for([@event, @event.users.build] do |f| %>    <%= f.hidden_field :user_id, value: current_user.id %>    <%= f.submit "RSVP", class: "btn btn-default" %>  <% end %>  

Please let me know if you need any extra code posting.

looping over records with condition

Posted: 09 Aug 2016 04:14 AM PDT

I have a Customer model that has the attribute private. This attribute is only visible for a total of 3 users in the database. If this method (check_box) gets checked by one of those 3 users the Customer is only visible by them.

I'm currently looping over all of the Customers like this:

<% @customers.where(:private => false).each do |single_customer| %>  

My question is how can I accomplish when one of the 3 users is signed in that :private => false gets changed to @customers.each do |single_customer| because then I don't want to filter the private attribute anymore.

rbenv gives me to long error report in shell when something happens with my rails app

Posted: 09 Aug 2016 05:53 AM PDT

rbenv gives me to long error report in shell when something happens with my rails app in development. I don't need this. How can I disable it?

Example:

Exiting  /home/kirill/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters  /connection_specification.rb:177:in `rescue in spec': Specified 'postgresql' for database adapter, but the gem is not loaded. Add `gem 'pg'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord). (Gem::LoadError)      from /home/kirill/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/connection_specification.rb:174:in `spec'      from /home/kirill/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-4.2.5/lib/active_record/connection_handling.rb:50:in `establish_connection'      from /home/kirill/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-4.2.5/lib/active_record/railtie.rb:120:in `block (2 levels) in <class:Railtie>'      from /home/kirill/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-4.2.5/lib/active_support/lazy_load_hooks.rb:38:in `instance_eval'      from /home/kirill/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-4.2.5/lib/active_support/lazy_load_hooks.rb:38:in `execute_hook'      from /home/kirill/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-4.2.5/lib/active_support/lazy_load_hooks.rb:28:in `block in on_load'      from /home/kirill/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-4.2.5/lib/active_support/lazy_load_hooks.rb:27:in `each'      from /home/kirill/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-4.2.5/lib/active_support/lazy_load_hooks.rb:27:in `on_load'      from /home/kirill/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-4.2.5/lib/active_record/railtie.rb:116:in `block in <class:Railtie>'      from /home/kirill/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-4.2.5/lib/rails/initializable.rb:30:in `instance_exec'      from /home/kirill/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-4.2.5/lib/rails/initializable.rb:30:in `run'      from /home/kirill/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-4.2.5/lib/rails/initializable.rb:55:in `block in run_initializers'      from /home/kirill/.rbenv/versions/2.3.1/lib/ruby/2.3.0/tsort.rb:228:in `block in tsort_each'      from /home/kirill/.rbenv/versions/2.3.1/lib/ruby/2.3.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'      from /home/kirill/.rbenv/versions/2.3.1/lib/ruby/2.3.0/tsort.rb:431:in `each_strongly_connected_component_from'      from /home/kirill/.rbenv/versions/2.3.1/lib/ruby/2.3.0/tsort.rb:349:in `block in each_strongly_connected_component'      from /home/kirill/.rbenv/versions/2.3.1/lib/ruby/2.3.0/tsort.rb:347:in `each'      from /home/kirill/.rbenv/versions/2.3.1/lib/ruby/2.3.0/tsort.rb:347:in `call'      from /home/kirill/.rbenv/versions/2.3.1/lib/ruby/2.3.0/tsort.rb:347:in `each_strongly_connected_component'      from /home/kirill/.rbenv/versions/2.3.1/lib/ruby/2.3.0/tsort.rb:226:in `tsort_each'      from /home/kirill/.rbenv/versions/2.3.1/lib/ruby/2.3.0/tsort.rb:205:in `tsort_each'      from /home/kirill/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-4.2.5/lib/rails/initializable.rb:54:in `run_initializers'      from /home/kirill/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-4.2.5/lib/rails/application.rb:352:in `initialize!'      from /home/kirill/Projects/kirill-zhuravlov-blog/config/environment.rb:5:in `<top (required)>'      from /home/kirill/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:274:in `require'      from /home/kirill/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:274:in `block in require'      from /home/kirill/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:240:in `load_dependency'      from /home/kirill/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:274:in `require'      from /home/kirill/Projects/kirill-zhuravlov-blog/config.ru:3:in `block in <main>'      from /home/kirill/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rack-1.6.4/lib/rack/builder.rb:55:in `instance_eval'      from /home/kirill/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rack-1.6.4/lib/rack/builder.rb:55:in `initialize'      from /home/kirill/Projects/kirill-zhuravlov-blog/config.ru:in `new'      from /home/kirill/Projects/kirill-zhuravlov-blog/config.ru:in `<main>'      from /home/kirill/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rack-1.6.4/lib/rack/builder.rb:49:in `eval'      from /home/kirill/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rack-1.6.4/lib/rack/builder.rb:49:in `new_from_string'      from /home/kirill/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rack-1.6.4/lib/rack/builder.rb:40:in `parse_file'      from /home/kirill/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rack-1.6.4/lib/rack/server.rb:299:in `build_app_and_options_from_config'      from /home/kirill/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rack-1.6.4/lib/rack/server.rb:208:in `app'      from /home/kirill/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-4.2.5/lib/rails/commands/server.rb:61:in `app'      from /home/kirill/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rack-1.6.4/lib/rack/server.rb:336:in `wrapped_app'      from /home/kirill/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-4.2.5/lib/rails/commands/server.rb:139:in `log_to_stdout'      from /home/kirill/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-4.2.5/lib/rails/commands/server.rb:78:in `start'      from /home/kirill/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:80:in `block in server'      from /home/kirill/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:75:in `tap'      from /home/kirill/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:75:in `server'      from /home/kirill/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:39:in `run_command!'      from /home/kirill/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-4.2.5/lib/rails/commands.rb:17:in `<top (required)>'      from bin/rails:4:in `require'      from bin/rails:4:in `<main>'  

But the actual problem is just my commented " #gem 'pg' " in gemfile. Im using latest LTS Ubuntu, ruby 2.3 and rails 4.2

Routing Error uninitialized constant rails

Posted: 09 Aug 2016 04:31 AM PDT

I'm getting this error.When I want to run te server on localhost:3000/api/v1/songs.json Routing Error uninitialized constant API::V1::SongsController. Thats my routes.rb file:

Rails.application.routes.draw do      namespace :api do           namespace :v1 do               resources :songs, only: [:index, :create, :update, :destroy]          end      end  # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html  end  

Routes

Routes match in priority from top to bottom

Helper  HTTP Verb   Path    Controller#Action  Path / Url        Path Match  api_v1_songs_path   GET /api/v1/songs(.:format)   api/v1/songs#index    POST    /api/v1/songs(.:format)   api/v1/songs#create    api_v1_song_path    PATCH   /api/v1/songs/:id(.:format)   api/v1/songs#update    PUT /api/v1/songs/:id(.:format)   api/v1/songs#update    DELETE  /api/v1/songs/:id(.:format)   api/v1/songs#destroy  

and thats my SongsController:

class Api::V1::SongsController < Api::V1::BaseController    def index      respond_with Song.all    end      def create      respond_with :api, :v1, Song.create(song_params)    end      def destroy      respond_with Song.destroy(params[:id])    end      def update      song = Song.find(params["id"])      song.update_attributes(song_params)      respond_with song, json: song    end      private      def song_params      params.require(:song).permit(:id, :name, :singer_name, :genre, :updated_at, :tag)    end  end  

Optimization Ruby on Rails (count)

Posted: 09 Aug 2016 04:46 AM PDT

How is it possible to optimize this code? (

(Many messages)

    def messages_count        total = 0        users.each do |u|          total += u.messages.size        end      total      end  

Thanks you

No comments:

Post a Comment