Thursday, November 17, 2016

scope for associations - Rails 4 | Fixed issues

scope for associations - Rails 4 | Fixed issues


scope for associations - Rails 4

Posted: 17 Nov 2016 08:10 AM PST

i would really appreciate if one could help me write a scope displaying the number of females (women) attending an event

models

user.rb  belongs_to :category_gender  has_many :payments    category_gender.rb  has_many :users    event.rb  belongs_to :user  has_many :payments    payment.rb  belongs_to :user  belongs_to :event  
  • event_payments: displays the payments made by users attending the event_id:7

Terminal

event = Event.find(7)  event_payments = event.payments    2.3.0 :054 > event_payments  [      [0] #<Payment:0x007fea72ac5b70> {                                 :id => 6,                              :email => "richill@gmail.com",                            :user_id => 4,                          :reference => "SPz_ruZ5om",                         :created_at => Wed, 16 Nov 2016 13:52:23 UTC +00:00,                         :updated_at => Wed, 16 Nov 2016 13:52:23 UTC +00:00,                           :event_id => 7,                 :stripe_customer_id => "cus_9YuZZAniFCZVxn",                  :stripe_payment_id => "ch_19GTpnAAe71J3vK0aj1gKryO",                 :event_payment_date => Wed, 16 Nov 2016 13:52:23 UTC +00:00,                             :status => "success"      }      [1] #<Payment:0x007fea72ac5b70> {                                 :id => 7,                              :email => "peter@gmail.com",                            :user_id => 5,                          :reference => "SPz_mnX4ul",                         :created_at => Wed, 16 Nov 2016 13:52:23 UTC +00:00,                         :updated_at => Wed, 16 Nov 2016 13:52:23 UTC +00:00,                           :event_id => 7,                 :stripe_customer_id => "cus_6FhLLMotYCCYvn",                  :stripe_payment_id => "ch_20GTunDDt87J3vK1sp4gPry9",                 :event_payment_date => Wed, 16 Nov 2016 13:52:23 UTC +00:00,                             :status => "success"      }  ]  

question: how do i write a scope to find all the payments made by females under an event?

if i write the below - i can find the first payment made is by a woman

event.payments.first.user.category_gender.name    2.3.0 :026 > event.payments.first.user.category_gender.name    Payment Load (0.2ms)  SELECT  "payments".* FROM "payments" WHERE "payments"."event_id" = ?  ORDER BY "payments"."id" ASC LIMIT 1  [["event_id", 7]]    User Load (0.1ms)  SELECT  "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1  [["id", 4]]    CategoryGender Load (0.1ms)  SELECT  "category_genders".* FROM "category_genders" WHERE "category_genders"."id" = ? LIMIT 1  [["id", 2]]   => "Female"   2.3.0 :027 >  

i tried the below scope to display all the payments made by females for an event, but no luck - tried a method as well but no luck. your help and explanation would be much appreciated on who to write this as a scope & a method:

event.rb  scope :females, -> { joins(payment: :category_gender).where('category_genders.name' => "Female") }    def females      self.payments.where('user.category_gender.name = ?', "Female")    end  

How do I populate an "attr_accessor" in my view?

Posted: 17 Nov 2016 08:07 AM PST

I'm using Rails 5. I have this model with the following "attr_accessor" …

class Scenario < ApplicationRecord    belongs_to :grading_rubric, optional: true    has_many :confidential_memo    has_many :scenario_roles, :dependent => :destroy    has_many :roles, :through => :scenario_roles      attr_accessor :roles_str      validates_presence_of :title    validates_presence_of :abstract      def roles_str      str = ""      roles.each do |role|        str = str.empty? ? "role.name\n" : "#{str}#{role.name}"      end      str    end     end  

In my view, I would like to display the output of the above "roles_str" method in my "roles_str" text area. I have this set up

<%= form_for @scenario, :url => url_for(:controller => 'scenarios', :action => 'create') do |f| %>  …      <%= f.text_area(:roles_str, cols: 40, rows: 20, :validate => true) %>  

but when I edit my object, this field is not populated. How do I populate it with the specified output from the model's "role_str" method?

Rails - find record with highest month/year

Posted: 17 Nov 2016 08:04 AM PST

I'm kinda stuck in a select query question: I have a Bill model, which contains two integer attributes: month and year. I would like to retrieve the more recent record (highest date) so I can check an attribute value on it. Any ideas for solving that problem, since month and year are independent attributes? Thanks!

Retrieving the correct model id

Posted: 17 Nov 2016 07:55 AM PST

I'm attempting to edit data from a model, but it keeps listing the User id instead of its own id. Why is that?

<% provide(:title, 'Activations') %>  <div class="row">   <div class="col-md-8">  <% if @user.activations.present? %>    <h3>Activations (<%= @user.activations.count %>)</h3>    <ol class="activations">      <%= render @activation %>    </ol>    <%= will_paginate @activation %>  <% end %>  </div>  </div>   </div>  

This is part of the partial that is being rendered

<span class="user"><%= link_to activation.id, edit_activation_path %></span>  

I've tried passing edit_activation_path(params[:id])The activation id is being listed correctly, but I don't know how to set the edit path with the id from the activation model.

Thank you for your help.

Rails - params not saving to database

Posted: 17 Nov 2016 07:38 AM PST

I'm building an events app using Rails and am trying to get to grips with the booking confirmation process. At the moment my MVC seems all over the place.

Here's my new booking form for free events which purely requires the quantity of spaces a user requires -

new.html.erb

<%= simple_form_for [@event, @booking], id: "new_booking" do |form| %>                      <% if @booking.errors.any? %>                          <h2><%= pluralize(@booking.errors.count, "error") %> prevented this Booking from saving:</h2>                    <ul>                          <% @booking.errors.full_messages.each do |message| %>                        <li><%= message %></li>                      <% end %>                    </ul>                  <% end %>                      <div class="form-group">                      <p>Please confirm the number of spaces you wish to reserve for this event.</p>                      <%= form.input :quantity, class: "form-control" %>                  </div>                     <p> This is a free event. No payment is required.</p>                       <div class="panel-footer">                            <%= form.submit :submit, label: 'Confirm Booking', class: "btn btn-primary" %>                         <% end %>                    </div>     

And here's my controller code -

bookings_controller.rb

 before_action :find_booking, only: [:show, :update]      before_action :find_event, only: [:show, :update]      before_action :authenticate_user!          def new          @event = Event.find(params[:event_id])          @booking = @event.bookings.new(quantity: params[:quantity])          @booking.user = current_user        end        def create            @event = Event.find(params[:event_id])          @booking = @event.bookings.new(booking_params)          @booking.user = current_user                if                   @booking.paid_booking                  flash[:success] = "Your place on our event has been booked"                  @booking.update_attributes!(booking_number: "MAMA" + '- ' + SecureRandom.hex(4).upcase)                  redirect_to event_booking_path(@event, @booking)              else                  flash[:error] = "Booking unsuccessful"                  render "new"              end      end        def free_booking              if                   @booking.free_booking                  @booking.update_attributes!(booking_number: "MAMA" + '- ' + SecureRandom.hex(4).upcase)                  redirect_to event_booking_path(@event, @booking)              else                  flash[:error] = "Booking unsuccessful"                  render "new"              end      end        def show          @event = Event.find(params[:event_id])          @booking = Booking.find_by(booking_number: params[:booking_number])      end          def update            if @booking.save              redirect_to event_booking_path(@event, @booking) , notice: "Booking was successfully updated!"          else              render 'new'          end      end          private        def booking_params          params.require(:booking).permit(:stripe_token, :booking_number, :quantity, :event_id, :stripe_charge_id, :total_amount)      end        def find_booking          @booking = Booking.find_by(booking_number: params[:booking_number])      end        def find_event          @event = Event.find(params[:event_id])      end            end   

When I check the booking on a console, the only params being saved are event_id and user_id - quantity is not saved for free bookings but it does get saved for paid bookings. Also, my booking confirmation show view has the following attributes included -

<%= @event.title %>  <%= @booking.quantity %>  <%= @booking.booking_number %>  

Of these three attributes, only the event.title shows on the page, the other two don't show at all. I'm completely stumped as to how or why this is happening. Would appreciate it if anyone can see something I'm not able to.

Design where all associations tie to a team / community

Posted: 17 Nov 2016 07:30 AM PST

I'm interested in hearing how people design and set this up as I'm fairly inexperienced with this scenario.

Take for example a Rails application that allow people to create teams. Each team can have many projects, comments, members and other resources.

How do you structure this to avoid deep linking f.ex:

nested_comment.root_comment.project.team

I see this becoming problematic quite quickly, causing both performance issues and in general not very comfortable to work with.

Routes will also become complicated if the team ID is to present always, f.ex: example.com/:team_name

resources :teams do    resources :projects do      resources :comments    end  end  

I know you can do shallow nesting, but the issue I see here is that you can use a slug but it will still require some deep linking. Do people use trees or something?

Modify batch files to make rails use newer version of ruby?

Posted: 17 Nov 2016 07:55 AM PST

Would it be sufficient to modify the existing batch files which reference the path to Rails's ruby.exe, or, am I missing the bigger picture?

Windows 7 OS, running rails s from a project folder I get this warning:
RubyDep: WARNING: Your Ruby is: 2.2.4 (buggy). Recommendation: install 2.2.5 or 2.3.1.

Using the Rails installer, I have Rails 4.2.5.1 installed here:
C:\RailsInstaller
and an older version of Ruby, here:
C:\RailsInstaller\Ruby2.2.0\bin\ruby.exe
...specifically
ruby 2.2.4p230 (2015-12-16 revision 53155) [i386-mingw32]

I have Ruby 2.3.1 installed:
C:\Ruby23-x64\bin\ruby.exe
specifically
ruby 2.3.1p112 (2016-04-26 revision 54768) [x64-mingw32]

I've updated my PATH so that C:\Ruby23-x64\bin; has precedence but Rails still invokes version 2.2.4 from C:\RailsInstaller\Ruby2.2.0\bin\ruby.exe when I invoke rails s.

In the rails project I've specified Ruby "2.3.1" in
C:\Users\user_name\rails_project.ruby-version

Also, if I add ruby '2.3.1' to the project Gemfile, I get this error msg and : Your Ruby version is 2.2.4, but your Gemfile specified 2.3.1

I am assuming I can't simply replace the 2.2 ruby.exe with the 2.3 ruby.exe? (Or the enclosing folders and all their contents...)

As I understand, neither rvm (per their FAQ, a resounding "NO" - but as of 2012 a cygwin env might be an option?) nor rbenv (per Mischa Taylor, the suggestion is to use pik ) nor pik(per their readme, "no longer maintained") are available for windows 7.

Would it be sufficient and adequate to simply modify the existing batch files which reference the path to Rails's ruby.exe? For example, change each of the bat_file_name.bat files in the C:\RailsInstaller\Ruby2.2.0\bin\ directory which read:

@ECHO OFF  IF NOT "%~f0" == "~f0" GOTO :WinNT  @"c:\RailsInstaller\Ruby2.2.0\bin\ruby.exe" "c:/RailsInstaller/Ruby2.2.0/bin/bat_file_name" %1 %2 %3 %4 %5 %6 %7 %8 %9  GOTO :EOF  :WinNT  @"c:\RailsInstaller\Ruby2.2.0\bin\ruby.exe" "%~dpn0" %*  

...to:

@ECHO OFF  IF NOT "%~f0" == "~f0" GOTO :WinNT  @"C:\Ruby23-x64\bin\ruby.exe" "c:/RailsInstaller/Ruby2.2.0/bin/bat_file_name" %1 %2 %3 %4 %5 %6 %7 %8 %9  GOTO :EOF  :WinNT  @"C:\Ruby23-x64\bin\ruby.exe" "%~dpn0" %*  

I notice that the slashes ( \ and / )are reversed the "c" for the RailsInstaller is lowercase, similar to how the git Bash app displays/uses drive names. I don't pretent to understand how all this works, but maybe swapping in "c:/Ruby23-x64/bin/ruby.exe"?

So maybe this:

@ECHO OFF  IF NOT "%~f0" == "~f0" GOTO :WinNT  @"c:/Ruby23-x64/bin/ruby.exe" "c:/RailsInstaller/Ruby2.2.0/bin/bat_file_name" %1 %2 %3 %4 %5 %6 %7 %8 %9  GOTO :EOF  :WinNT  @"c:/Ruby23-x64/bin/ruby.exe" "%~dpn0" %*  

Apologies if this is off-topic but I can't afford a Mac and I've tried setting up Rails on Ubuntu and run into similar problems. Of note, I have a basic bare bones project working on Win7 that does not note the "buggy" version, but it also defaults the old version of Ruby. At the very least I would like to get the Rails server to run using the version of Ruby I tell it to. Thanks!

Rails join model not effectively working in my complex application

Posted: 17 Nov 2016 07:02 AM PST

I have an Order, a Product and in between the join model Booking.

It has some peculiarities:

  • The Booking join model doesn't need the product model to still be present. (So bookings can stay on an order even though the product has been deleted.) Done by: belongs_to :product, optional: true
  • All three models are in one view: the store.
  • The booking are rendered a-synchronically.

The crux of the problem seems to be that a normal order has_many bookings relationship seems not to be working.

Been having issues for week so need to get to the bottom of it. How did I build it?

Migrations

# timestamp_create_products.rb  class CreateProducts < ActiveRecord::Migration[5.0]    def change      create_table :products do |t|        t.string :name        t.text :description        t.references :category, index: true, foreign_key: true          t.timestamps      end    end  end    # timestamp_bookings_orders.rb  class CreateBookings < ActiveRecord::Migration[5.0]    def change      create_table :bookings do |t|        t.belongs_to :order, index: true, foreign_key: true        t.belongs_to :product, index: true, foreign_key: true        t.string :product_name        t.integer :product_quantity          t.timestamps      end        add_monetize :bookings, :product_price    end  end    # timestamp_create_orders.rb  class CreateOrders < ActiveRecord::Migration[5.0]    def change      create_table :orders do |t|        t.column :status, :integer        t.timestamps      end        add_monetize :orders, :total    end  end  

booking.rb

class Booking < ApplicationRecord    # Money: product_price    monetize :product_price_cents    # Associaties    belongs_to :product, optional: true    belongs_to :order    # Validations    validates :product_quantity, presence: true, numericality: { only_integer: true, greater_than: 0 }    validates :order, presence: true    validates_uniqueness_of :order_id #, scope: :product_id    # Actions    after_save do      oder.sum_all_bookings    end      def total      product_price * product_quantity    end  end  

order.rb

class Order < ApplicationRecord    # Money: total    monetize :total_cents    # Statuses    enum status: { open: 0, paid: 1, stored: 2, sent: 3, problem: 4 }    # Associations    belongs_to :customer, class_name: 'User'    accepts_nested_attributes_for :customer    has_many :bookings, dependent: :destroy      def sum_all_bookings      bookings = self.bookings      sum = 0      bookings.each do |booking|        sum += booking.product_quantity * booking.product_price_cents      end      self.total_cents = sum    end      def self.sum_of_all_orders      sum = Order.sum(:total_cents)      Money.new(sum)    end  end  

product.rb

class Product < ApplicationRecord    # Money: price    monetize :price_cents, :allow_nil => true, :numericality => { :greater_than_or_equal_to => 0 }    # Associaties    belongs_to :category    has_many :orders, through: :bookings    has_many :bookings, dependent: :nullify    has_many :pictures, as: :imageable, dependent: :destroy    # Validaties    validates :name, presence: true, length: { maximum: 100 }    validates :description, presence: true, length: { maximum: 500 }  end  

bookings_controller.rb

class BookingsController < ApplicationController    before_action :set_order, only: [:create, :update, :destroy]    before_action :set_booking, only: [:update, :destroy]      def create      product = Product.find(id: params[:booking][:product_id])      unless @order.bookings.find_by(product_id: product.id)        booking = Booking.new(booking_params,                              :product_name  => @product.name,                               :product_price => @product.price )        booking.save        @order.bookings.create(booking: booking)      else         booking = @order.bookings.find_by(product_id: product.id)        booking.product_quantity = params[:booking][:product_quantity]        booking.save      end      @order.save  end  

I have tried many different version of building a bookings_controller. I think the mistake is lays somewhere else.

Any ideas or possibly the solution?

Capybara test multi domain environment

Posted: 17 Nov 2016 06:53 AM PST

We have multiple domains hosted, and each is responding with different layouts and content.

class HostNameTest < Capybara::Rails::TestCase      test "can't visit without correct host" do      visit "/"      assert_content page, "service not available"    end      test "homepage responds to correct host" do      Capybara.app_host = "http://somedomain.local"      Capybara.always_include_port = true        visit "/"      page.has_content?("somedomain")    end      test "homepage responds to another correct host" do      Capybara.app_host = "http://someotherdomain.local"      Capybara.always_include_port = true        visit "/"      page.has_content?("someotherdomain")    end  end  

default access localhost:3000 is rendering an error message. that is working fine.

even thought we have not setted up somedomain.local the tests are passing. in reality it should render "service not available", because somedomain.localisn't defined.

it seems that we set up the host wrong for each test.

how can we test hostnames and how can we set an default hostname for all future tests?

Rails query on combined unique columns

Posted: 17 Nov 2016 06:50 AM PST

I have 3 tables ride, rider, horse

I want to create a query to retrieve @results that find unique matches of the horse and rider combination associated with ride

class Ride < ActiveRecord::Base    belongs_to :horse     belongs_to :ride    ...    class Rider < ActiveRecord::Base    has_many :rides    ...     class Horse < ActiveRecord::Base    has_many :rides    ...  

ride holds rider_id, horse_id, and score

With @results, I want to count total rides on combination and do math on ride.score (total per rider/horse combo etc)

I am looking for a performant way to do this. I though perhaps the best approach might be a left outer join but I am not sure how to go about this.

My initial incomplete attempt was:

@results=Ride.left_outer_joins(:riders).distinct.select('rides.*, COUNT(rides.*) AS rides_count').group('rider.last_name')  

I thought I would add try adding the join for horses once it got it working with riders, but the initial query gave me error:

undefined method `left_outer_joins' for #<XXXX>  

Rails: 4.2 Postgres: 9.3.15

Any thoughts on aproaches to getting my @results?

Serialize an ActiveRecord instance, and all subrecords

Posted: 17 Nov 2016 06:44 AM PST

Hi so I'm working on a project where users can manage their own forum, and I'd like when for when a new user logs in that they are given a pre populated demo forum they can play about with to test the projects features. It seems to me the best way to do this would be to take an already existing record, serialise it and all its sub records and then deserialize for each new user. However if I do Forum.serializable_hash I only get the attributes of Forum and not the records that belong to Forum.

Is there a way for me to do this?

Ruby on Rails Secrets.yml

Posted: 17 Nov 2016 06:48 AM PST

I just want to make sure I'm not misinterpreting this but if I am using environment variables in my config/secrets.yml file should I still be concerned about pushing it to a public repo? I see many posts about adding this file to git-ignore to protect credentials but if they're passed in as environment variables it shouldn't be a problem correct?

undefined method `model_name' with simple_form on Rails 5

Posted: 17 Nov 2016 06:24 AM PST

I'm getting an undefined method 'model_name' error with simple_form when I want to edit a basic post on Rails 5.

show.html.haml:

= link_to "Edit", edit_post_path(@post)

edit.html.haml:

= simple_form_for @post do |f|      = f.input :title      = f.input :link      = f.input :description        = f.button :submit  

posts_controller.rb:

def show      @post = Post.find(params[:id])  end    def edit  end    def update      if @post.update(post_params)          redirect_to @post      else          render 'edit'      end  end  

Any idea?

Ruby on rails and JSON to create Select form [duplicate]

Posted: 17 Nov 2016 06:25 AM PST

This question already has an answer here:

I want to create a form like that :

<select>    <option>  </select>  

with ruby on rails, but it is for countries (and there is a lot of countries in the world haha), so I don't want to write everyone on my view, so I want to put a JSON file with all countries, and get theme in my option items ( with each method maybe )

I don't know where I have to put my json file in my rails app and how call it in my view,

does someone could help me ?

Rails saving arrays to separate rows in the DB

Posted: 17 Nov 2016 06:38 AM PST

Could someone take a look at my code and let me know if there is a better way to do this, or even correct where I'm going wrong please? I am trying to create a new row for each venue and variant.

Example:

venue_ids => ["1","2"], variant_ids=>["10"]  

So, I would want to add in a row which has a venue_id of 1, with variant_id of 10. And a venue_id of 2, with variant_id of 10

I got this working, and it's now passing in my two arrays. I think I am almost there I'm not sure the .each is the right way to do it, but I think that I'm on the right track haha. I have it submitting, however, where would I put my @back_bar.save? because this might cause issues as it won't redirect

Thanks in advance.

def create    @back_bar = BackBar.new    @venues = params[:venue_ids]    @productid = params[:product_id]    @variants = params[:variant_ids]      # For each venue we have in the array, grab the ID.    @venues.each do |v|      @back_bar.venue_id = v      # Then for each variant we associate the variant ID with that venue.      @variants.each do |pv|        @back_bar.product_variant_id = pv          # Add in our product_id        @back_bar.product_id = @productid        # Save the venue and variant to the DB.          if @back_bar.save          flash[:success] = "#{@back_bar.product.name} has been added to #{@back_bar.venue.name}'s back bar."          # Redirect to the back bar page          redirect_to back_bars_path        else          flash[:alert] = "A selected variant for #{@back_bar.product.name} is already in #{@back_bar.venue.name}'s back bar."           # Redirect to the product page          redirect_to discoveries_product_path(@back_bar.product_id)        end      end # Variants end    end # Venues end  end    private      def back_bar_params      params.require(:back_bar).permit(:venue_id,                                       :product_id,                                       :product_variant_id)    end  

how to run rails 2 project on rails 4

Posted: 17 Nov 2016 05:07 AM PST

hey I want to run the fedena project (that is actually on rails 2) on rails 4. Any idea how can I do that. Do i have to update the app using rake app:update or something else. please help me out. I can't find a proper solution. Thanks

unable to start rails server with foreman start

Posted: 17 Nov 2016 06:31 AM PST

I have this Procfile given in my existing Project which I need to setup.

web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb  worker: bundle exec rake jobs:work  sidekiq_worker: env DB_POOL=${SIDEKIQ_DB_POOL:-10} bundle exec sidekiq -c ${SIDEKIQ_CONCURRENCY:-4} -q $RAILS_ENV"_magplus_background_job" -i ${DYNO#worker.}  app_build_sidekiq_worker: env DB_POOL=${APP_BUILD_SIDEKIQ_DB_POOL:-3} bundle exec sidekiq -c ${APP_BUILD_SIDEKIQ_CONCURRENCY:-1} -q $RAILS_ENV"_app_build_background_job" -i ${DYNO#worker.}  message_queue_worker: bundle exec rails runner 'MessageQueueWorker.new.perform'  message_queue_publisher: bundle exec rails runner 'Caerbannog::Queue.publish'  

I installed foreman like this.

MAC-Nod-Dev:service-plus dev$ gem install foreman  Successfully installed foreman-0.82.0  1 gem installed  

When I do foreman start I get the following error:

18:19:04 web.1                      | started with pid 8129  18:19:04 worker.1                   | started with pid 8130  18:19:04 sidekiq_worker.1           | started with pid 8131  18:19:04 app_build_sidekiq_worker.1 | started with pid 8132  18:19:04 message_queue_worker.1     | started with pid 8133  18:19:04 message_queue_publisher.1  | started with pid 8134  18:19:07 web.1                      | I, [2016-11-17T18:19:07.856228 #8129]  INFO -- : Refreshing Gem list  18:19:08 sidekiq_worker.1           | missing argument: -i  18:19:08 sidekiq_worker.1           | /Users/dev/.rvm/gems/ruby-2.3.1@serviceplus/gems/sidekiq-3.3.3/lib/sidekiq/cli.rb:338:in `parse_options'  18:19:08 sidekiq_worker.1           | /Users/dev/.rvm/gems/ruby-2.3.1@serviceplus/gems/sidekiq-3.3.3/lib/sidekiq/cli.rb:208:in `setup_options'  18:19:08 sidekiq_worker.1           | /Users/dev/.rvm/gems/ruby-2.3.1@serviceplus/gems/sidekiq-3.3.3/lib/sidekiq/cli.rb:38:in `parse'  18:19:08 sidekiq_worker.1           | /Users/dev/.rvm/gems/ruby-2.3.1@serviceplus/gems/sidekiq-3.3.3/bin/sidekiq:7:in `<top (required)>'  18:19:08 sidekiq_worker.1           | /Users/dev/.rvm/gems/ruby-2.3.1@serviceplus/bin/sidekiq:23:in `load'  18:19:08 sidekiq_worker.1           | /Users/dev/.rvm/gems/ruby-2.3.1@serviceplus/bin/sidekiq:23:in `<main>'  18:19:08 sidekiq_worker.1           | /Users/dev/.rvm/gems/ruby-2.3.1@serviceplus/bin/ruby_executable_hooks:15:in `eval'  18:19:08 sidekiq_worker.1           | /Users/dev/.rvm/gems/ruby-2.3.1@serviceplus/bin/ruby_executable_hooks:15:in `<main>'  18:19:08 app_build_sidekiq_worker.1 | missing argument: -i  18:19:08 app_build_sidekiq_worker.1 | /Users/dev/.rvm/gems/ruby-2.3.1@serviceplus/gems/sidekiq-3.3.3/lib/sidekiq/cli.rb:338:in `parse_options'  18:19:08 app_build_sidekiq_worker.1 | /Users/dev/.rvm/gems/ruby-2.3.1@serviceplus/gems/sidekiq-3.3.3/lib/sidekiq/cli.rb:208:in `setup_options'  18:19:08 app_build_sidekiq_worker.1 | /Users/dev/.rvm/gems/ruby-2.3.1@serviceplus/gems/sidekiq-3.3.3/lib/sidekiq/cli.rb:38:in `parse'  18:19:08 app_build_sidekiq_worker.1 | /Users/dev/.rvm/gems/ruby-2.3.1@serviceplus/gems/sidekiq-3.3.3/bin/sidekiq:7:in `<top (required)>'  18:19:08 app_build_sidekiq_worker.1 | /Users/dev.rvm/gems/ruby-2.3.1@serviceplus/bin/sidekiq:23:in `load'  18:19:08 app_build_sidekiq_worker.1 | /Users/dev/.rvm/gems/ruby-2.3.1@serviceplus/bin/sidekiq:23:in `<main>'  18:19:08 app_build_sidekiq_worker.1 | /Users/dev/.rvm/gems/ruby-2.3.1@serviceplus/bin/ruby_executable_hooks:15:in `eval'  18:19:08 app_build_sidekiq_worker.1 | /Users/dev/.rvm/gems/ruby-2.3.1@serviceplus/bin/ruby_executable_hooks:15:in `<main>'  18:19:09 app_build_sidekiq_worker.1 | exited with code 1  18:19:09 system                     | sending SIGTERM to all processes  18:19:09 sidekiq_worker.1           | exited with code 1  18:19:09 worker.1                   | rake aborted!  18:19:09 worker.1                   | SignalException: SIGTERM  18:19:09 worker.1                   | /Users/dev/.rvm/gems/ruby-2.3.1@serviceplus/gems/actionpack-4.2.6/lib/action_dispatch/http/response.rb:76:in `require'  18:19:09 worker.1                   | /Users/dev/.rvm/gems/ruby-2.3.1@serviceplus/gems/actionpack-4.2.6/lib/action_dispatch/http/response.rb:76:in `<class:Response>'  18:19:09 worker.1                   | /Users/dev/.rvm/gems/ruby-2.3.1@serviceplus/gems/actionpack-4.2.6/lib/action_dispatch/http/response.rb:36:in `<module:ActionDispatch>'  18:19:09 worker.1                   | /Users/dev/.rvm/gems/ruby-2.3.1@serviceplus/gems/actionpack-4.2.6/lib/action_dispatch/http/response.rb:7:in `<top (required)>'  18:19:09 worker.1                   | /Users/dev/.rvm/gems/ruby-2.3.1@serviceplus/gems/actionpack-4.2.6/lib/action_controller/metal/live.rb:1:in `require'  18:19:09 worker.1                   | /Users/dev/.rvm/gems/ruby-2.3.1@serviceplus/gems/actionpack-4.2.6/lib/action_controller/metal/live.rb:1:in `<top (required)>'  18:19:09 worker.1                   | /Users/dev/.rvm/gems/ruby-2.3.1@serviceplus/gems/actionpack-4.2.6/lib/action_controller.rb:4:in `require'  18:19:09 worker.1                   | /Users/dev/.rvm/gems/ruby-2.3.1@serviceplus/gems/actionpack-4.2.6/lib/action_controller.rb:4:in `<top (required)>'  18:19:09 worker.1                   | /Users/dev/.rvm/gems/ruby-2.3.1@serviceplus/gems/actionpack-4.2.6/lib/action_controller/railtie.rb:2:in `require'  18:19:09 worker.1                   | /Users/dev/.rvm/gems/ruby-2.3.1@serviceplus/gems/actionpack-4.2.6/lib/action_controller/railtie.rb:2:in `<top (required)>'  18:19:09 worker.1                   | /Users/dev/.rvm/gems/ruby-2.3.1@serviceplus/gems/activerecord-4.2.6/lib/active_record/railtie.rb:9:in `require'  18:19:09 worker.1                   | /Users/dev/.rvm/gems/ruby-2.3.1@serviceplus/gems/activerecord-4.2.6/lib/active_record/railtie.rb:9:in `<top (required)>'  18:19:09 worker.1                   | /Users/dev/.rvm/gems/ruby-2.3.1@serviceplus/gems/railties-4.2.6/lib/rails/all.rb:13:in `require'  18:19:09 worker.1                   | /Users/dev/.rvm/gems/ruby-2.3.1@serviceplus/gems/railties-4.2.6/lib/rails/all.rb:13:in `block in <top (required)>'  18:19:09 worker.1                   | /Users/dev/.rvm/gems/ruby-2.3.1@serviceplus/gems/railties-4.2.6/lib/rails/all.rb:11:in `each'  18:19:09 worker.1                   | /Users/dev/.rvm/gems/ruby-2.3.1@serviceplus/gems/railties-4.2.6/lib/rails/all.rb:11:in `<top (required)>'  18:19:09 worker.1                   | /Users/dev/munam/projects/magplus/service-plus/config/application.rb:3:in `require'  18:19:09 worker.1                   | /Users/dev/munam/projects/magplus/service-plus/config/application.rb:3:in `<top (required)>'  18:19:09 worker.1                   | /Users/dev/munam/projects/magplus/service-plus/Rakefile:4:in `require'  18:19:09 worker.1                   | /Users/dev/munam/projects/magplus/service-plus/Rakefile:4:in `<top (required)>'  18:19:09 worker.1                   | /Users/dev/.rvm/gems/ruby-2.3.1@serviceplus/bin/ruby_executable_hooks:15:in `eval'  18:19:09 worker.1                   | /Users/dev/.rvm/gems/ruby-2.3.1@serviceplus/bin/ruby_executable_hooks:15:in `<main>'  18:19:09 worker.1                   | (See full trace by running task with --trace)  18:19:09 message_queue_publisher.1  | terminated by SIGTERM  18:19:09 message_queue_worker.1     | terminated by SIGTERM  18:19:09 worker.1                   | exited with code 1  18:19:14 system                     | sending SIGKILL to all processes  

And the system breaks but strangely when run the rails server normally with either rails s or foreman run rails s it runs smoothly but I need to it with foreman else I need to start different tabs and obviously that is a better way. I will be really thankful if someone helps me out here.

Thanks a lot in advance!

Rails 4.0.x how route root to specified action?

Posted: 17 Nov 2016 06:28 AM PST

I've following code in my routes.rb file

resources :contacts, controller: 'contact_us', only: [:new, :create] do    root :to => 'contact_us#new'  end  

in my understanding the above route for contacts will only support :new and :create actions, and with specified controller controller: 'contact_us' also it with root / it will redirect to #new action but when I hit http://localhost:3000/contact-us in my browser it says

Unknown action
The action 'index' could not be found for ContactUsController

I've upgraded the rails version from 3.2.19 to 4.0.13 and ruby to 2.0.0p481

the old code was working fine with rails 3.2.19 and ruby 1.8.7

resources :contacts,    :controller => 'contact_us',    :only       => [:new, :create]  match 'contact_us' => 'contact_us#new'  

if I only change match with get in above code it throws this error

/home/vagrant/.rvm/gems/ruby-2.0.0-p481/gems/actionpack-4.0.13/lib/action_dispatch/routing/route_set.rb:430:in `add_route': Invalid route name, already in use: 'contact_us' (ArgumentError)

You may have defined two routes with the same name using the :as option, or you may be overriding a route already defined by a resource with the same naming. For the latter, you can restrict the routes created with resources as explained here:

Verifying a time field before save in Rails

Posted: 17 Nov 2016 04:39 AM PST

I need to verify a time_select before save it in Rails.

I added a before_action who calls a method to verify the value. In this case, it's a time_select called "start_hour", and it have a select box for hours and a select box for minutes.

By inspecting it in controller, we don't have a formatted string, only many paramateres with fragments, for example: "start_hour(1i)" with two characters of hours, "start_hour(2i)" with two characters of minutes ...

Is there a way to inspect the final value, like "12:00"?

Rails - format Time in API response

Posted: 17 Nov 2016 06:42 AM PST

i have a model places in relationship with the model opening_times.

In my places_controller i have this:

def index    places = Place.all      if places      render json: {        status: :ok,        result: places.as_json(          only: [            :id,            :name,          ],          include: [            { opening_times: {only: [:dayWeek, :open, :close]}},          ]        )      }    else      render json: { errors: 'invalid request' }, status: 422    end  end    private    def place_params      params.require(:place).permit(:user_id, :name)    end  

The open and close columns in DB are time.

How can i force to return a format time as %H:%M?

Ruby based job scheduling library

Posted: 17 Nov 2016 04:19 AM PST

I'm searching for a Ruby based job scheduling library, something like Quartz but for Ruby/Rails projects. I was not able to find any analogs, so maybe you can help me.

Thank you in advance.

Exception NameError in Rack application when call FactoryGirl

Posted: 17 Nov 2016 04:08 AM PST

I encounter the problem when trying to execute RSpec integration test. Please let me introduce my current setup for integration test first.

Our company app has 2 projects: Saver and Getter. Both projects share the same database but different models. We also have Elasticsearch database. Saver project mainly is used to create data and bulk data to elasticsearch database. Getter project is used to read data from elasticsearch. For easier imagination, please take a look the structure:

Structure

My duty is that covers tests for Getter project. Most of the tests is unit test, but some tests I have to write as integration test because I need to call to Saver project to populate and bulk data to elasticsearch.

In Saver side, I public an internal API (a controller) to receive creation data request from Getter. And thank for FactoryGirl I can create data and bulk this data to elasticsearch. After receiving response from Saver, Getter can query and continuously run tests. Of course, that leads to problem that I have to start Saver application in test environment when I want to run tests on Getter.

Everything works correctly on my local until I deploy to the AWS server. It shows the errors on the Saver side when a creation data request from Getter send to.

[ 2016-11-17 11:03:22.9049 13662/7f7e8199a700 age/Cor/Con/InternalUtils.cpp:112 ]: [Client 1-67] Sending 502 response: application did not send a complete response  Started POST "/internal_api/elastic_search/syn_product_variant" for 127.0.0.1 at 2016-11-17 11:03:22 +0000  Processing by InternalAPI::V1::ElasticSearchController#syn_product_variant as JSON  Completed 500 Internal Server Error in 1ms (ActiveRecord: 0.0ms)  App 13698 stderr: [ 2016-11-17 11:03:22.9729 13717/0x00000001c243d0(Worker 1) utils.rb:87 ]: *** Exception NameError in Rack application object (uninitialized constant FactoryGirl) (process 13717, thread  0x00000001c243d0(Worker 1)):  App 13698 stderr:       from /home/ec2-user/rails_apps/hiptruck/releases/20161117085315/app/integration_test/variant_builder.rb:3:in `build'  App 13698 stderr:       from /home/ec2-user/rails_apps/hiptruck/releases/20161117085315/app/controllers/internal_api/v1/elastic_search_controller.rb:3:in `syn_product_variant'  App 13698 stderr:       from /home/ec2-user/rails_apps/hiptruck/shared/bundle/ruby/2.3.0/gems/actionpack-4.2.7/lib/action_controller/metal/implicit_render.rb:4:in `send_action'  App 13698 stderr:       from /home/ec2-user/rails_apps/hiptruck/shared/bundle/ruby/2.3.0/gems/actionpack-4.2.7/lib/abstract_controller/base.rb:198:in `process_action'  App 13698 stderr:       from /home/ec2-user/rails_apps/hiptruck/shared/bundle/ruby/2.3.0/gems/actionpack-4.2.7/lib/action_controller/metal/rendering.rb:10:in `process_action'  App 13698 stderr:       from /home/ec2-user/rails_apps/hiptruck/shared/bundle/ruby/2.3.0/gems/actionpack-4.2.7/lib/abstract_controller/callbacks.rb:20:in `block in process_action'  App 13698 stderr:       from /home/ec2-user/rails_apps/hiptruck/shared/bundle/ruby/2.3.0/gems/activesupport-4.2.7/lib/active_support/callbacks.rb:117:in `call'  App 13698 stderr:       from /home/ec2-user/rails_apps/hiptruck/shared/bundle/ruby/2.3.0/gems/activesupport-4.2.7/lib/active_support/callbacks.rb:555:in `block (2 levels) in compile'  App 13698 stderr:       from /home/ec2-user/rails_apps/hiptruck/shared/bundle/ruby/2.3.0/gems/activesupport-4.2.7/lib/active_support/callbacks.rb:505:in `call'  App 13698 stderr:       from /home/ec2-user/rails_apps/hiptruck/shared/bundle/ruby/2.3.0/gems/activesupport-4.2.7/lib/active_support/callbacks.rb:92:in `__run_callbacks__'  App 13698 stderr:       from /home/ec2-user/rails_apps/hiptruck/shared/bundle/ruby/2.3.0/gems/activesupport-4.2.7/lib/active_support/callbacks.rb:778:in `_run_process_action_callbacks'  App 13698 stderr:       from /home/ec2-user/rails_apps/hiptruck/shared/bundle/ruby/2.3.0/gems/activesupport-4.2.7/lib/active_support/callbacks.rb:81:in `run_callbacks'  App 13698 stderr:       from /home/ec2-user/rails_apps/hiptruck/shared/bundle/ruby/2.3.0/gems/actionpack-4.2.7/lib/abstract_controller/callbacks.rb:19:in `process_action'  App 13698 stderr:       from /home/ec2-user/rails_apps/hiptruck/shared/bundle/ruby/2.3.0/gems/actionpack-4.2.7/lib/action_controller/metal/rescue.rb:29:in `process_action'  App 13698 stderr:       from /home/ec2-user/rails_apps/hiptruck/shared/bundle/ruby/2.3.0/gems/actionpack-4.2.7/lib/action_controller/metal/instrumentation.rb:32:in `block in process_action'  App 13698 stderr:       from /home/ec2-user/rails_apps/hiptruck/shared/bundle/ruby/2.3.0/gems/activesupport-4.2.7/lib/active_support/notifications.rb:164:in `block in instrument'  App 13698 stderr:       from /home/ec2-user/rails_apps/hiptruck/shared/bundle/ruby/2.3.0/gems/activesupport-4.2.7/lib/active_support/notifications/instrumenter.rb:20:in `instrument'  App 13698 stderr:       from /home/ec2-user/rails_apps/hiptruck/shared/bundle/ruby/2.3.0/gems/activesupport-4.2.7/lib/active_support/notifications.rb:164:in `instrument'  App 13698 stderr:       from /home/ec2-user/rails_apps/hiptruck/shared/bundle/ruby/2.3.0/gems/actionpack-4.2.7/lib/action_controller/metal/instrumentation.rb:30:in `process_action'  App 13698 stderr:       from /home/ec2-user/rails_apps/hiptruck/shared/bundle/ruby/2.3.0/gems/actionpack-4.2.7/lib/action_controller/metal/params_wrapper.rb:250:in `process_action'  App 13698 stderr:       from /home/ec2-user/rails_apps/hiptruck/shared/bundle/ruby/2.3.0/gems/activerecord-4.2.7/lib/active_record/railties/controller_runtime.rb:18:in `process_action'  App 13698 stderr:       from /home/ec2-user/rails_apps/hiptruck/shared/bundle/ruby/2.3.0/gems/actionpack-4.2.7/lib/abstract_controller/base.rb:137:in `process'  App 13698 stderr:       from /home/ec2-user/rails_apps/hiptruck/shared/bundle/ruby/2.3.0/gems/actionview-4.2.7/lib/action_view/rendering.rb:30:in `process'  App 13698 stderr:       from /home/ec2-user/rails_apps/hiptruck/shared/bundle/ruby/2.3.0/gems/rack-mini-profiler-0.10.1/lib/mini_profiler/profiling_methods.rb:76:in `block in profile_method'  App 13698 stderr:       from /home/ec2-user/rails_apps/hiptruck/shared/bundle/ruby/2.3.0/gems/actionpack-4.2.7/lib/action_controller/metal.rb:196:in `dispatch'  App 13698 stderr:       from /home/ec2-user/rails_apps/hiptruck/shared/bundle/ruby/2.3.0/gems/actionpack-4.2.7/lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'  App 13698 stderr:       from /home/ec2-user/rails_apps/hiptruck/shared/bundle/ruby/2.3.0/gems/actionpack-4.2.7/lib/action_controller/metal.rb:237:in `block in action'  App 13698 stderr:       from /home/ec2-user/rails_apps/hiptruck/shared/bundle/ruby/2.3.0/gems/actionpack-4.2.7/lib/action_dispatch/routing/route_set.rb:74:in `dispatch'  App 13698 stderr:       from /home/ec2-user/rails_apps/hiptruck/shared/bundle/ruby/2.3.0/gems/actionpack-4.2.7/lib/action_dispatch/routing/route_set.rb:43:in `serve'  App 13698 stderr:       from /home/ec2-user/rails_apps/hiptruck/shared/bundle/ruby/2.3.0/gems/actionpack-4.2.7/lib/action_dispatch/journey/router.rb:43:in `block in serve'  App 13698 stderr:       from /home/ec2-user/rails_apps/hiptruck/shared/bundle/ruby/2.3.0/gems/actionpack-4.2.7/lib/action_dispatch/journey/router.rb:30:in `each'  App 13698 stderr:       from /home/ec2-user/rails_apps/hiptruck/shared/bundle/ruby/2.3.0/gems/actionpack-4.2.7/lib/action_dispatch/journey/router.rb:30:in `serve'  App 13698 stderr:       from /home/ec2-user/rails_apps/hiptruck/shared/bundle/ruby/2.3.0/gems/actionpack-4.2.7/lib/action_dispatch/routing/route_set.rb:817:in `call'  App 13698 stderr:       from /home/ec2-user/rails_apps/hiptruck/shared/bundle/ruby/2.3.0/gems/omniauth-1.3.1/lib/omniauth/strategy.rb:186:in `call!'  App 13698 stderr:       from /home/ec2-user/rails_apps/hiptruck/shared/bundle/ruby/2.3.0/gems/omniauth-1.3.1/lib/omniauth/strategy.rb:164:in `call'  App 13698 stderr:       from /home/ec2-user/rails_apps/hiptruck/shared/bundle/ruby/2.3.0/gems/warden-1.2.6/lib/warden/manager.rb:35:in `block in call'  App 13698 stderr:       from /home/ec2-user/rails_apps/hiptruck/shared/bundle/ruby/2.3.0/gems/warden-1.2.6/lib/warden/manager.rb:34:in `catch'  App 13698 stderr:       from /home/ec2-user/rails_apps/hiptruck/shared/bundle/ruby/2.3.0/gems/warden-1.2.6/lib/warden/manager.rb:34:in `call'  App 13698 stderr:       from /home/ec2-user/rails_apps/hiptruck/shared/bundle/ruby/2.3.0/gems/rack-1.6.4/lib/rack/etag.rb:24:in `call'  App 13698 stderr:       from /home/ec2-user/rails_apps/hiptruck/shared/bundle/ruby/2.3.0/gems/rack-1.6.4/lib/rack/conditionalget.rb:38:in `call'  App 13698 stderr:       from /home/ec2-user/rails_apps/hiptruck/shared/bundle/ruby/2.3.0/gems/rack-1.6.4/lib/rack/head.rb:13:in `call'  App 13698 stderr:       from /home/ec2-user/rails_apps/hiptruck/shared/bundle/ruby/2.3.0/gems/remotipart-1.2.1/lib/remotipart/middleware.rb:27:in `call'  App 13698 stderr:       from /home/ec2-user/rails_apps/hiptruck/shared/bundle/ruby/2.3.0/gems/actionpack-4.2.7/lib/action_dispatch/middleware/params_parser.rb:27:in `call'  App 13698 stderr:       from /home/ec2-user/rails_apps/hiptruck/shared/bundle/ruby/2.3.0/gems/actionpack-4.2.7/lib/action_dispatch/middleware/flash.rb:260:in `call'  App 13698 stderr:       from /home/ec2-user/rails_apps/hiptruck/shared/bundle/ruby/2.3.0/gems/rack-1.6.4/lib/rack/session/abstract/id.rb:225:in `context'  App 13698 stderr:       from /home/ec2-user/rails_apps/hiptruck/shared/bundle/ruby/2.3.0/gems/rack-1.6.4/lib/rack/session/abstract/id.rb:220:in `call'  App 13698 stderr:       from /home/ec2-user/rails_apps/hiptruck/shared/bundle/ruby/2.3.0/gems/actionpack-4.2.7/lib/action_dispatch/middleware/cookies.rb:560:in `call'  App 13698 stderr:       from /home/ec2-user/rails_apps/hiptruck/shared/bundle/ruby/2.3.0/gems/activerecord-4.2.7/lib/active_record/query_cache.rb:36:in `call'  App 13698 stderr:       from /home/ec2-user/rails_apps/hiptruck/shared/bundle/ruby/2.3.0/gems/airbrake-5.4.4/lib/airbrake/rack/middleware.rb:22:in `call'  App 13698 stderr:       from /home/ec2-user/rails_apps/hiptruck/shared/bundle/ruby/2.3.0/gems/activerecord-4.2.7/lib/active_record/connection_adapters/abstract/connection_pool.rb:653:in `call'  App 13698 stderr:       from /home/ec2-user/rails_apps/hiptruck/shared/bundle/ruby/2.3.0/gems/actionpack-4.2.7/lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'  App 13698 stderr:       from /home/ec2-user/rails_apps/hiptruck/shared/bundle/ruby/2.3.0/gems/activesupport-4.2.7/lib/active_support/callbacks.rb:88:in `__run_callbacks__'  App 13698 stderr:       from /home/ec2-user/rails_apps/hiptruck/shared/bundle/ruby/2.3.0/gems/activesupport-4.2.7/lib/active_support/callbacks.rb:778:in `_run_call_callbacks'  App 13698 stderr:       from /home/ec2-user/rails_apps/hiptruck/shared/bundle/ruby/2.3.0/gems/activesupport-4.2.7/lib/active_support/callbacks.rb:81:in `run_callbacks'  App 13698 stderr:       from /home/ec2-user/rails_apps/hiptruck/shared/bundle/ruby/2.3.0/gems/actionpack-4.2.7/lib/action_dispatch/middleware/callbacks.rb:27:in `call'  App 13698 stderr:       from /home/ec2-user/rails_apps/hiptruck/shared/bundle/ruby/2.3.0/gems/actionpack-4.2.7/lib/action_dispa  App 13698 stderr: tch/middleware/reloader.rb:73:in `call'  App 13698 stderr:       from /home/ec2-user/rails_apps/hiptruck/shared/bundle/ruby/2.3.0/gems/actionpack-4.2.7/lib/action_dispatch/middleware/remote_ip.rb:78:in `call'  App 13698 stderr:       from /home/ec2-user/rails_apps/hiptruck/shared/bundle/ruby/2.3.0/gems/actionpack-4.2.7/lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'  App 13698 stderr:       from /home/ec2-user/rails_apps/hiptruck/shared/bundle/ruby/2.3.0/gems/actionpack-4.2.7/lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'  App 13698 stderr:       from /home/ec2-user/rails_apps/hiptruck/shared/bundle/ruby/2.3.0/gems/railties-4.2.7/lib/rails/rack/logger.rb:38:in `call_app'  App 13698 stderr:       from /home/ec2-user/rails_apps/hiptruck/shared/bundle/ruby/2.3.0/gems/railties-4.2.7/lib/rails/rack/logger.rb:20:in `block in call'  App 13698 stderr:       from /home/ec2-user/rails_apps/hiptruck/shared/bundle/ruby/2.3.0/gems/activesupport-4.2.7/lib/active_support/tagged_logging.rb:68:in `block in tagged'  App 13698 stderr:       from /home/ec2-user/rails_apps/hiptruck/shared/bundle/ruby/2.3.0/gems/activesupport-4.2.7/lib/active_support/tagged_logging.rb:26:in `tagged'  App 13698 stderr:       from /home/ec2-user/rails_apps/hiptruck/shared/bundle/ruby/2.3.0/gems/activesupport-4.2.7/lib/active_support/tagged_logging.rb:68:in `tagged'  App 13698 stderr:       from /home/ec2-user/rails_apps/hiptruck/shared/bundle/ruby/2.3.0/gems/railties-4.2.7/lib/rails/rack/logger.rb:20:in `call'  App 13698 stderr:       from /home/ec2-user/rails_apps/hiptruck/shared/bundle/ruby/2.3.0/gems/request_store-1.3.1/lib/request_store/middleware.rb:9:in `call'  App 13698 stderr:       from /home/ec2-user/rails_apps/hiptruck/shared/bundle/ruby/2.3.0/gems/actionpack-4.2.7/lib/action_dispatch/middleware/request_id.rb:21:in `call'  App 13698 stderr:       from /home/ec2-user/rails_apps/hiptruck/shared/bundle/ruby/2.3.0/gems/rack-1.6.4/lib/rack/methodoverride.rb:22:in `call'  App 13698 stderr:       from /home/ec2-user/rails_apps/hiptruck/shared/bundle/ruby/2.3.0/gems/rack-1.6.4/lib/rack/runtime.rb:18:in `call'  App 13698 stderr:       from /home/ec2-user/rails_apps/hiptruck/shared/bundle/ruby/2.3.0/gems/activesupport-4.2.7/lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'  App 13698 stderr:       from /home/ec2-user/rails_apps/hiptruck/shared/bundle/ruby/2.3.0/gems/rack-1.6.4/lib/rack/lock.rb:17:in `call'  App 13698 stderr:       from /home/ec2-user/rails_apps/hiptruck/shared/bundle/ruby/2.3.0/gems/actionpack-4.2.7/lib/action_dispatch/middleware/static.rb:120:in `call'  App 13698 stderr:       from /home/ec2-user/rails_apps/hiptruck/shared/bundle/ruby/2.3.0/gems/rack-1.6.4/lib/rack/sendfile.rb:113:in `call'  App 13698 stderr:       from /home/ec2-user/rails_apps/hiptruck/shared/bundle/ruby/2.3.0/gems/rack-mini-profiler-0.10.1/lib/mini_profiler/profiler.rb:171:in `call'  App 13698 stderr:       from /home/ec2-user/rails_apps/hiptruck/shared/bundle/ruby/2.3.0/gems/railties-4.2.7/lib/rails/engine.rb:518:in `call'  App 13698 stderr:       from /home/ec2-user/rails_apps/hiptruck/shared/bundle/ruby/2.3.0/gems/railties-4.2.7/lib/rails/application.rb:165:in `call'  App 13698 stderr:       from /home/ec2-user/.rvm/gems/ruby-2.3.1/gems/passenger-5.0.30/src/ruby_supportlib/phusion_passenger/rack/thread_handler_extension.rb:97:in `process_request'  App 13698 stderr:       from /home/ec2-user/.rvm/gems/ruby-2.3.1/gems/passenger-5.0.30/src/ruby_supportlib/phusion_passenger/request_handler/thread_handler.rb:160:in `accept_and_process_next_request'  App 13698 stderr:       from /home/ec2-user/.rvm/gems/ruby-2.3.1/gems/passenger-5.0.30/src/ruby_supportlib/phusion_passenger/request_handler/thread_handler.rb:113:in `main_loop'  App 13698 stderr:       from /home/ec2-user/.rvm/gems/ruby-2.3.1/gems/passenger-5.0.30/src/ruby_supportlib/phusion_passenger/request_handler.rb:416:in `block (3 levels) in start_threads'  App 13698 stderr:       from /home/ec2-user/.rvm/gems/ruby-2.3.1/gems/passenger-5.0.30/src/ruby_supportlib/phusion_passenger/utils.rb:113:in `block in create_thread_and_abort_on_exception'  [ 2016-11-17 11:03:22.9735 13662/7f7e8199a700 age/Cor/Con/InternalUtils.cpp:112 ]: [Client 1-68] Sending 502 response: application did not send a complete response  Started POST "/internal_api/elastic_search/syn_product_variant" for 127.0.0.1 at 2016-11-17 11:03:22 +0000  Processing by InternalAPI::V1::ElasticSearchController#syn_product_variant as JSON  Completed 500 Internal Server Error in 1ms (ActiveRecord: 0.0ms)  App 13698 stderr: [ 2016-11-17 11:03:23.0028 13717/0x00000001c243d0(Worker 1) utils.rb:87 ]: *** Exception NameError in Rack application object (uninitialized constant FactoryGirl) (process 13717, thread0  x00000001c243d0(Worker 1)):  

I run passenger on the server and I use capistrano to deploy both projects.

Here is my gem file in Saver project:

def personal_gems_from_env    ENV['DEVELOPMENT_GEMS'].split(' ').each { |gem_name| gem(gem_name) } if ENV['DEVELOPMENT_GEMS']  end    source 'https://rubygems.org'    ruby '2.3.1'    gem 'puma'  gem 'rails', '4.2.7'  gem 'pg', group: [:development, :production]  gem 'resque', require: "resque/server"  gem 'resque-scheduler'  gem 'airbrake', '~> 5.4'  gem 'hominid'  gem "attr_extras"    gem 'redis'  gem 'redis-namespace'  gem "redis-rails"  gem 'rubyzip'  gem 'google_drive'  gem 'paperclip'  gem 'aws-sdk', '~> 2.3'  gem 'unicorn'  gem 'will_paginate', '~> 3.0'  gem 'pg_search'    gem 'wicked_pdf', '~> 1.0', '>= 1.0.3'  gem 'wkhtmltopdf-binary-edge', '~> 0.12.2.1', group: [:development]  gem 'protected_attributes'    gem 'json'  gem 'activeresource'  gem 'shopify_api'  gem 'htmlentities', '~> 4.3.1'  gem 'nokogiri'  gem 'pundit'  gem 'devise'  gem 'omniauth'  gem 'omniauth-google-oauth2'  gem 'react-rails', '~> 1.6.1'  gem 'barby'  gem 'koala', '~> 2.2'  gem 'acts-as-taggable-on', '~> 3.5'  gem 'paypal-sdk-rest'  gem 'stripe', '~> 1.36'  gem 'mimemagic'  gem "therubyracer"  gem "less-rails" #Sprockets (what Rails 3.1 uses for its asset pipeline) supports LESS  gem "twitter-bootstrap-rails"  gem 'react-bootstrap-rails'  gem 'bootstrap-sass'  gem 'newrelic_rpm'  gem 'browserify-rails'  gem 'font-awesome-rails'  gem 'config'  gem 'sass-rails', '~> 4.0.2'  gem 'uglifier', '>= 1.3.0'  gem 'coffee-rails', '~> 4.0.0'  gem 'jquery-rails'  gem 'turbolinks'  gem 'jbuilder', '~> 1.2'  gem 'bcrypt'  gem 'active_model_serializers'  gem "awesome_print", require:"ap"  gem 'active_median'  gem 'hashie'  gem 'byebug', group: [:development, :test]  gem 'datagrid', '~> 1.3.9'  gem 'bootstrap-editable-rails'  gem 'paper_trail'  gem 'jquery-ui-rails'  gem 'remotipart'  gem 'haml'  gem 'httmultiparty' # which also includes 'httparty'  gem "jquery-fileupload-rails"  gem 'colored'  gem 'amoeba', '~> 3.0.0'  gem 'text', '~> 1.3.0'  gem 'pusher'  gem 'bootstrap-wysihtml5-rails'  gem 'swiftype'  gem 'sanitize'  gem 'premailer-rails'  gem 'closure_tree', git: 'https://github.com/mceachen/closure_tree.git'  gem 'resque-lock-timeout'  gem 'elasticsearch-rails'  gem 'elasticsearch-model'  gem 'imgix', '~> 1.1.0'  gem 'whenever', require: false  gem 'whenever-elasticbeanstalk', git: 'https://github.com/jufemaiz/whenever-elasticbeanstalk.git', branch: 'feature/aws-2.3'  gem 'globalphone', '~> 1.0', '>= 1.0.1'  gem 'activerecord-import', '~> 0.11.0'  group :doc do    gem 'sdoc', require: false  end    gem 'rack-mini-profiler', require: false  gem 'axlsx', '~> 2.0', '>= 2.0.1'    group :development, :test do    gem 'dotenv-rails'  end    group :development do    gem 'annotate', github: 'ctran/annotate_models', branch: 'develop'    gem 'thin'    gem 'pry'    gem 'better_errors'    gem 'binding_of_caller'    gem 'rubocop'    gem 'rails_best_practices'    gem 'meta_request'    gem "pry-rails"    gem 'quiet_assets'    gem 'letter_opener'    gem 'capistrano', '~> 3.5.0'    gem 'capistrano-rails'    gem 'capistrano-bundler'    gem 'capistrano-rvm'    gem 'capistrano-passenger'    gem 'capistrano-dotenv-tasks', require: false    gem "bullet"      gem 'rails-dev-boost', :git => 'git://github.com/thedarkone/rails-dev-boost.git', :require => 'rails_development_boost'    gem 'rb-fsevent', '>= 0.9.1'      personal_gems_from_env  end    group :test do    gem 'rspec-rails'    gem 'mocha', "~> 0.10.0", :require => false    gem 'simplecov', '0.6.1'    gem 'simplecov-rcov', '0.2.3'    gem 'factory_girl_rails', '~> 4.7'    gem 'faker', '~> 1.6', '>= 1.6.3'      gem 'capybara'  end    group :production do    gem 'rails_12factor'  end    group :assets do    gem 'ejs'    gem 'fog-aws'    gem 'asset_sync', require: true  end    gem 'braintree', '~> 2.61', '>= 2.61.1'  gem 'liquid'  gem 'sitemap_generator', '~> 5.1'  gem 'fog-aws'  

I also searched the error but the result is limited. I found one useful comment from this discussion but I don't know how to fix based on that suggestion.

error deploying my rails application with capisrano on aws

Posted: 17 Nov 2016 04:08 AM PST

I followed the guide on deploying to aws ec2 https://www.sitepoint.com/deploy-your-rails-app-to-aws/.

I am using ubuntu 16 server.

Everything has installed perfectly on the server but when i run cap production deploy --trace this is the output.

** Invoke production (first_time)  

** Execute production ** Invoke load:defaults (first_time) ** Execute load:defaults ** Invoke rvm:hook (first_time) ** Execute rvm:hook ** Invoke rvm:check (first_time) ** Execute rvm:check cap aborted! Net::SSH::ConnectionTimeout: Net::SSH::ConnectionTimeout /var/lib/gems/2.1.0/gems/net-ssh-3.2.0/lib/net/ssh/transport/session.rb:90:in rescue in initialize' /var/lib/gems/2.1.0/gems/net-ssh-3.2.0/lib/net/ssh/transport/session.rb:57:ininitialize' /var/lib/gems/2.1.0/gems/net-ssh-3.2.0/lib/net/ssh.rb:232:in new' /var/lib/gems/2.1.0/gems/net-ssh-3.2.0/lib/net/ssh.rb:232:instart' /var/lib/gems/2.1.0/gems/sshkit-1.11.4/lib/sshkit/backends/connection_pool.rb:59:in call' /var/lib/gems/2.1.0/gems/sshkit-1.11.4/lib/sshkit/backends/connection_pool.rb:59:inwith' /var/lib/gems/2.1.0/gems/sshkit-1.11.4/lib/sshkit/backends/netssh.rb:155:in with_ssh' /var/lib/gems/2.1.0/gems/sshkit-1.11.4/lib/sshkit/backends/netssh.rb:108:inexecute_command' /var/lib/gems/2.1.0/gems/sshkit-1.11.4/lib/sshkit/backends/abstract.rb:141:in block in create_command_and_execute' /var/lib/gems/2.1.0/gems/sshkit-1.11.4/lib/sshkit/backends/abstract.rb:141:intap' /var/lib/gems/2.1.0/gems/sshkit-1.11.4/lib/sshkit/backends/abstract.rb:141:in create_command_and_execute' /var/lib/gems/2.1.0/gems/sshkit-1.11.4/lib/sshkit/backends/abstract.rb:60:incapture' /var/lib/gems/2.1.0/gems/capistrano-rvm-0.1.2/lib/capistrano/tasks/rvm.rake:9:in block (3 levels) in <top (required)>' /var/lib/gems/2.1.0/gems/sshkit-1.11.4/lib/sshkit/backends/abstract.rb:29:ininstance_exec' /var/lib/gems/2.1.0/gems/sshkit-1.11.4/lib/sshkit/backends/abstract.rb:29:in run' /var/lib/gems/2.1.0/gems/sshkit-1.11.4/lib/sshkit/runners/parallel.rb:12:inblock (2 levels) in execute' Errno::ETIMEDOUT: Connection timed out - connect(2) for 172.31.11.127:22 /usr/lib/ruby/2.1.0/socket.rb:65:in connect' /usr/lib/ruby/2.1.0/socket.rb:65:inconnect_internal' /usr/lib/ruby/2.1.0/socket.rb:140:in connect' /usr/lib/ruby/2.1.0/socket.rb:338:inblock in tcp' /usr/lib/ruby/2.1.0/socket.rb:232:in each' /usr/lib/ruby/2.1.0/socket.rb:232:inforeach' /usr/lib/ruby/2.1.0/socket.rb:328:in tcp' /var/lib/gems/2.1.0/gems/net-ssh-3.2.0/lib/net/ssh/transport/session.rb:70:ininitialize' /var/lib/gems/2.1.0/gems/net-ssh-3.2.0/lib/net/ssh.rb:232:in new' /var/lib/gems/2.1.0/gems/net-ssh-3.2.0/lib/net/ssh.rb:232:instart' /var/lib/gems/2.1.0/gems/sshkit-1.11.4/lib/sshkit/backends/connection_pool.rb:59:in call' /var/lib/gems/2.1.0/gems/sshkit-1.11.4/lib/sshkit/backends/connection_pool.rb:59:inwith' /var/lib/gems/2.1.0/gems/sshkit-1.11.4/lib/sshkit/backends/netssh.rb:155:in with_ssh' /var/lib/gems/2.1.0/gems/sshkit-1.11.4/lib/sshkit/backends/netssh.rb:108:inexecute_command' /var/lib/gems/2.1.0/gems/sshkit-1.11.4/lib/sshkit/backends/abstract.rb:141:in block in create_command_and_execute' /var/lib/gems/2.1.0/gems/sshkit-1.11.4/lib/sshkit/backends/abstract.rb:141:intap' /var/lib/gems/2.1.0/gems/sshkit-1.11.4/lib/sshkit/backends/abstract.rb:141:in create_command_and_execute' /var/lib/gems/2.1.0/gems/sshkit-1.11.4/lib/sshkit/backends/abstract.rb:60:incapture' /var/lib/gems/2.1.0/gems/capistrano-rvm-0.1.2/lib/capistrano/tasks/rvm.rake:9:in block (3 levels) in <top (required)>' /var/lib/gems/2.1.0/gems/sshkit-1.11.4/lib/sshkit/backends/abstract.rb:29:ininstance_exec' /var/lib/gems/2.1.0/gems/sshkit-1.11.4/lib/sshkit/backends/abstract.rb:29:in run' /var/lib/gems/2.1.0/gems/sshkit-1.11.4/lib/sshkit/runners/parallel.rb:12:inblock (2 levels) in execute' Tasks: TOP => rvm:check

this is my production.rb

server '172.31.11.127', user: 'deploy', roles: %w{web app db}  

and

and my deploy.rb

set :branch, :master  

set :deploy_to, '/home/deploy/rd'

set :pty, true

set :linked_files, %w{config/database.yml config/application.yml}

set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system public/uploads}

set :keep_releases, 5

set :rvm_type, :user

set :rvm_ruby_version, 'ruby 2.1.5'

set :puma_rackup, -> { File.join(current_path, 'config.ru') }

set :puma_state, "#{shared_path}/tmp/pids/puma.state"

set :puma_pid, "#{shared_path}/tmp/pids/puma.pid"

set :puma_bind, "unix://#{shared_path}/tmp/sockets/puma.sock" #accept array for multi-bind

set :puma_conf, "#{shared_path}/puma.rb"

set :puma_access_log, "#{shared_path}/log/puma_error.log"

set :puma_error_log, "#{shared_path}/log/puma_access.log"

set :puma_role, :app

set :puma_env, fetch(:rack_env, fetch(:rails_env, 'production'))

set :puma_threads, [0, 8]

set :puma_workers, 0

set :puma_worker_timeout, nil

set :puma_init_active_record, true

set :puma_preload_app, false

i've tried severally and still getting the same output. What is wrong?

production server dont show images

Posted: 17 Nov 2016 04:03 AM PST

Can you help me? Here is my server. http://46.101.160.4/ In header-courusel i should have images, but he is not display. here is my code :

index.html.erb

          <!-- THE FIRST SLIDE-->          <li>            <!-- FIRST SLIDE OVERLAY -->            <div class="slider_overlay"></div>             <!-- FIRST SLIDE MAIN IMAGE -->            <img src="assets/doroga1.jpg" />            <!-- FIRST SLIDE CAPTION-->            <div class="slider_caption">              <h2>Пассажирские перевозки <br>Донбасс - Крым </h2>              <p>Ежедневно в обе стороны</p>                         </div>          </li>  

here is my style.css.scss

.slider_area{    float: left;    display: inline;    width: 100%;    position: relative;   }  .slider_overlay {     background: none repeat scroll 0 0 #242434;     height: 100%;     opacity: 0.8;     position: absolute;     right: 0;     top: 0;     width: 100%;     z-index: 9;   }  

Optimal database design to store array of options in Rails

Posted: 17 Nov 2016 04:13 AM PST

I have two sets of 'Users' - Customers and Suppliers.

A supplier can select a group of 'areas' they choose to service. There are currently 8 areas, ie: A1, A2, B2, Etc. When a customer makes an enquiry I will need to find suppliers who match the area that the customer has specified.

I'm new to database design and I'm wondering if there is an optimal way to store the 'areas' chosen by the supplier under the circumstances above.

For example, do I add an extra column to the user database which holds an array of areas or do I set up another separate table with a belongs_to relationship with the users?

If it helps, I am using Ruby Rails and have one model for all types of 'users'.

How to create dynamic attribute in rails for Active Record update method

Posted: 17 Nov 2016 04:13 AM PST

I have some variables that I get from the Get/Post requests =>

params[:status], params[:value] #:value has the value of the :status

and I would love to use the update method of the active record to update the record (validation needs to be run). How can I then create a dynamic query like

@user.update(status: value)  

I have tried this.

attribute = { params[:status] => params[:value] }  user.update(attribute)  

but this does not call any validation. Validation is IMPORTANT for me here.

What are partials in ruby on rails

Posted: 17 Nov 2016 07:52 AM PST

I am trying to figure out how partials works in rails.

Here is code :

<%= render "layouts/appended_pages", pages: {partial: "items",                                               collection: @results,                                               locals: {user_flag: false}} %>  

I understand that this render will render _appended_pages but what will do part with pages: ? how it works

ruby on rails installed successfully but project not opening on localhost

Posted: 17 Nov 2016 04:17 AM PST

I downloaded a website based on ruby on rails on my machine and tried to run it on my localhost. but it is not running. i have installed rails 4.0.2 and ruby 2.2.4p230. when i run the commands like cd welspun(the name of the folder where i stored the website files) and rails s i get the following message on cmd. i do not understand how to tackle this issue. i am using windows 7. please help me out. i have no knowledge of ruby on rails. please help me out.

C:\Sites>cd welspun    C:\Sites\welspun>rails s  C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/activesupport-4.0.2/lib/act  ive_support/values/time_zone.rb:282: warning: circular argument reference - now  C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/sqlite3-1.3.9-x86-mingw32/l  ib/sqlite3.rb:6:in `require': cannot load such file -- sqlite3/sqlite3_native (L  oadError)          from C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/sqlite3-1.3.9-x86-mingw32/lib/sqlite3.rb:6:in `rescue in <top (required)>'          from C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/sqlite3-1.3.9-x86-mingw32/lib/sqlite3.rb:2:in `<top (required)>'          from C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/bundler-1.13.6/lib/bundler/runtime.rb:91:in `require'          from C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/bundler-1.13.6/lib/bundler/runtime.rb:91:in `block (2 levels) in require'          from C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/bundler-1.13.6/lib/bundler/runtime.rb:86:in `each'          from C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/bundler-1.13.6/lib/bundler/runtime.rb:86:in `block in require'          from C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/bundler-1.13.6/lib/bundler/runtime.rb:75:in `each'          from C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/bundler-1.13.6/lib/bundler/runtime.rb:75:in `require'          from C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/bundler-1.13.6/lib/bundler.rb:106:in `require'          from C:/Sites/welspun/config/application.rb:7:in `<top (required)>'          from C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/railties-4.0.2/lib/rails/commands.rb:74:in `require'          from C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/railties-4.0.2/lib/rails/commands.rb:74:in `block in <top (required)>'          from C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/railties-4.0.2/lib/rails/commands.rb:71:in `tap'          from C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/railties-4.0.2/lib/rails/commands.rb:71:in `<top (required)>'          from bin/rails:4:in `require'          from bin/rails:4:in `<main>'    C:\Sites\welspun>rails s  C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/activesupport-4.0.2/lib/act  ive_support/values/time_zone.rb:282: warning: circular argument reference - now  C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/sqlite3-1.3.9-x86-mingw32/l  ib/sqlite3.rb:6:in `require': cannot load such file -- sqlite3/sqlite3_native (L  oadError)          from C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/sqlite3-1.3.9-x86-mingw32/lib/sqlite3.rb:6:in `rescue in <top (required)>'          from C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/sqlite3-1.3.9-x86-mingw32/lib/sqlite3.rb:2:in `<top (required)>'          from C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/bundler-1.13.6/lib/bundler/runtime.rb:91:in `require'          from C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/bundler-1.13.6/lib/bundler/runtime.rb:91:in `block (2 levels) in require'          from C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/bundler-1.13.6/lib/bundler/runtime.rb:86:in `each'          from C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/bundler-1.13.6/lib/bundler/runtime.rb:86:in `block in require'          from C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/bundler-1.13.6/lib/bundler/runtime.rb:75:in `each'          from C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/bundler-1.13.6/lib/bundler/runtime.rb:75:in `require'          from C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/bundler-1.13.6/lib/bundler.rb:106:in `require'          from C:/Sites/welspun/config/application.rb:7:in `<top (required)>'          from C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/railties-4.0.2/lib/rails/commands.rb:74:in `require'          from C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/railties-4.0.2/lib/rails/commands.rb:74:in `block in <top (required)>'          from C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/railties-4.0.2/lib/rails/commands.rb:71:in `tap'          from C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/railties-4.0.2/lib/rails/commands.rb:71:in `<top (required)>'          from bin/rails:4:in `require'          from bin/rails:4:in `<main>'    C:\Sites\welspun>  

Create a file from text input and pass it to Carrierwave in Rails

Posted: 17 Nov 2016 02:41 AM PST

A user inputs text data which I would like to store as a CSV file. First I figured I need to save the form data in a temp file and then feed it to my CarrierWave uploader.

So I have this uploader, whose job is to store the file:

class InputDataFile < ApplicationRecord      mount_uploader :uploaded_file, InputDataFileUploader    after_create :store_form_data_in_a_csv      def store_form_data_in_a_csv      file_src = File.join(Rails.root,"/public/tmp/{self.job_request.user_id}/#{random_number}.csv")      file = File.open(file_src, 'w+')        CSV.open(file, "wb") do |csv|        csv << self.job_request.input_data.split      end        uploader = InputDataFileUploader.new      uploader.store!(file)        # delete the temp file     end    end  

This is my though layout, but since it's not working I need some kind of input.

All rails test fail with error "no implicit conversion of nil into String"

Posted: 17 Nov 2016 02:52 AM PST

My tests used to work, but now they all fail with the following error and stack trace :

TypeError: no implicit conversion of nil into String      vendor/bundle/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/postgresql/utils.rb:24:in `quote_ident'      vendor/bundle/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/postgresql/utils.rb:24:in `quoted'      vendor/bundle/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/postgresql/quoting.rb:31:in `quote_table_name'      vendor/bundle/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/postgresql_adapter.rb:738:in `column_definitions'      vendor/bundle/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/postgresql/schema_statements.rb:186:in `columns'      vendor/bundle/gems/activerecord-4.2.5.1/lib/active_record/fixtures.rb:750:in `column_names'      vendor/bundle/gems/activerecord-4.2.5.1/lib/active_record/fixtures.rb:742:in `timestamp_column_names'      vendor/bundle/gems/activerecord-4.2.5.1/lib/active_record/fixtures.rb:627:in `block in table_rows'      vendor/bundle/gems/activerecord-4.2.5.1/lib/active_record/fixtures.rb:621:in `each'      vendor/bundle/gems/activerecord-4.2.5.1/lib/active_record/fixtures.rb:621:in `map'      vendor/bundle/gems/activerecord-4.2.5.1/lib/active_record/fixtures.rb:621:in `table_rows'      vendor/bundle/gems/activerecord-4.2.5.1/lib/active_record/fixtures.rb:526:in `block (3 levels) in create_fixtures'      vendor/bundle/gems/activerecord-4.2.5.1/lib/active_record/fixtures.rb:524:in `each'      vendor/bundle/gems/activerecord-4.2.5.1/lib/active_record/fixtures.rb:524:in `block (2 levels) in create_fixtures'      vendor/bundle/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `block in transaction'      vendor/bundle/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/abstract/transaction.rb:184:in `within_new_transaction'      vendor/bundle/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `transaction'      vendor/bundle/gems/activerecord-4.2.5.1/lib/active_record/fixtures.rb:523:in `block in create_fixtures'      vendor/bundle/gems/activerecord-4.2.5.1/lib/active_record/connection_adapters/postgresql/referential_integrity.rb:17:in `disable_referential_integrity'      vendor/bundle/gems/activerecord-4.2.5.1/lib/active_record/fixtures.rb:508:in `create_fixtures'      vendor/bundle/gems/activerecord-4.2.5.1/lib/active_record/fixtures.rb:979:in `load_fixtures'      vendor/bundle/gems/activerecord-4.2.5.1/lib/active_record/fixtures.rb:941:in `setup_fixtures'      vendor/bundle/gems/activerecord-4.2.5.1/lib/active_record/fixtures.rb:826:in `before_setup'      vendor/bundle/gems/minitest-5.9.1/lib/minitest/test.rb:105:in `block (3 levels) in run'      vendor/bundle/gems/minitest-5.9.1/lib/minitest/test.rb:204:in `capture_exceptions'      vendor/bundle/gems/minitest-5.9.1/lib/minitest/test.rb:104:in `block (2 levels) in run'      vendor/bundle/gems/minitest-5.9.1/lib/minitest/test.rb:255:in `time_it'      vendor/bundle/gems/minitest-5.9.1/lib/minitest/test.rb:103:in `block in run'      vendor/bundle/gems/minitest-5.9.1/lib/minitest.rb:348:in `on_signal'      vendor/bundle/gems/minitest-5.9.1/lib/minitest/test.rb:275:in `with_info_handler'      vendor/bundle/gems/minitest-5.9.1/lib/minitest/test.rb:102:in `run'      vendor/bundle/gems/minitest-5.9.1/lib/minitest.rb:799:in `run_one_method'      vendor/bundle/gems/minitest-5.9.1/lib/minitest.rb:322:in `run_one_method'      vendor/bundle/gems/minitest-5.9.1/lib/minitest.rb:310:in `block (2 levels) in run'      vendor/bundle/gems/minitest-5.9.1/lib/minitest.rb:309:in `each'      vendor/bundle/gems/minitest-5.9.1/lib/minitest.rb:309:in `block in run'      vendor/bundle/gems/minitest-5.9.1/lib/minitest.rb:348:in `on_signal'      vendor/bundle/gems/minitest-5.9.1/lib/minitest.rb:335:in `with_info_handler'      vendor/bundle/gems/minitest-5.9.1/lib/minitest.rb:308:in `run'      vendor/bundle/gems/minitest-5.9.1/lib/minitest.rb:158:in `block in __run'      vendor/bundle/gems/minitest-5.9.1/lib/minitest.rb:158:in `map'      vendor/bundle/gems/minitest-5.9.1/lib/minitest.rb:158:in `__run'      vendor/bundle/gems/minitest-5.9.1/lib/minitest.rb:135:in `run'      vendor/bundle/gems/minitest-5.9.1/lib/minitest.rb:62:in `block in autorun'  

I ran be rake db:drop && be rake db:create && be rake db:migrate && be rake db:schema:dump && be rake db:test:prepare to make sure my database is clean (where be is an alias for bundle exec)

How can I make my tests run correctly again?

EDIT : please tell me how I can improve my question if you're downvoting it.

No comments:

Post a Comment