Monday, January 16, 2017

How to add an identifier in a row if any cell for that row is changed in excel? | Fixed issues

How to add an identifier in a row if any cell for that row is changed in excel? | Fixed issues


How to add an identifier in a row if any cell for that row is changed in excel?

Posted: 16 Jan 2017 08:13 AM PST

Is there a way in excel to mark the rows with an identifier if any cell in that row is changed without using vb scripts and using a formula ?

Such that while parsing the excel, i can get only those rows which are changed and then i can easily compare those changed rows with the values in the database.

The reason i need to do that is because:

  1. It is a bulk import and each sheet can have 50,000 to million rows.

  2. Data in each row needs to compare with 3-4 database tables

  3. I cannot add vb scripts to those excel sheets because the excel sheets are exported through the same application.

Or is there any other way to efficiently do the bulk import? I'm using the Roo gem and already using the each_row_streaming method.

Where is the controller of Devise? how to add a variable in controller devise/registrations-action:edit - Rails 4

Posted: 16 Jan 2017 08:09 AM PST

  1. I am using the gem "devise". I am trying to define a variable/instance called @cards in my "controller"=>"devise/registrations", "action"=>"edit".
  2. i have followed the below steps but i still get the error: undefined method cards_with_booked_events' for nil:NilClass

could one tell me where i am going wrong? below is what i currently have in place:

Override the Devise sessions controller actions:

# app/controllers/sessions_controller.rb  class SessionsController < Devise::SessionsController      def edit      # add custom logic here      @cards = Card.all       super    end  end  

Register the controller:

# app/config/routes.rb  devise_for :users, :controllers => {:sessions => "sessions"}  

Rails can a class variable be assigned within a controller's instance method?

Posted: 16 Jan 2017 07:45 AM PST

In Rails, can I create a class variable that can be shared between the different instance methods? Just trying to avoid an unnecessary call if possible. Sorry guys, taking this project over last minute from another developer. I haven't coded Rails in 2 years and excited to be getting back into it.

Here's example code:

class Api::VideoEpisodesController < Api::ApiController      # GET /video_episodes    # GET /video_episodes.json    def index      # can I share @@video_episodes with the set_video_episode method?      # or just @video_episodes = VideoEpisode.where(season_number: params[:season_number]) because can't do what I intend?      @@video_episodes = VideoEpisode.where(season_number: params[:season_number])    end        # GET /video_episodes/1    # GET /video_episodes/1.json    def show      set_video_episode    end      private      # Use callbacks to share common setup or constraints between actions.      def set_video_episode        # would I be able to access @@video_episodes from the index method or        # is the best way to go instance variable:         # @video_episodes = VideoEpisode.where(season_number: params[:season_number])        # @video_episode = @video_episodes.find(params[:id])        @video_episode = @@video_episodes.find(params[:id])      end    end  

Using Rails, how do I execute a javascript file on a specific page in the application?

Posted: 16 Jan 2017 08:05 AM PST

I am attempting to load a javascript file onto my rails application, but only for a specific page in my application, not the homepage. How would I get my javascript file to load for a specific page is using rails.

The javascript I have now, located in programs.js in assets/javascript, looks like this:

document.addEventListener('DOMContentLoaded', (event) => {   let program = document.getElementsByClassName('program-name')   console.log(program)   })  

Again, the code itself works fine. The problem is that it executes for the homepage, and not for any particular page that I want it to. How would I go about getting the code to execute for a specific page within my rails application?

FriendlyID - Assigning a slug before it is saved

Posted: 16 Jan 2017 07:42 AM PST

I've an ActivityType model that creates a dynamic page after being created, with a slug equalling the ActivityType's slug.

If a page already exists with this slug, it is throwing a validation error, so I'm trying to change the slug of the ActivityType before it is saved, assuming that a Dynamic page already exists with that slug.

I've written the following code:

def check_and_change_slug    n = 1    slug = title    while DynamicPage.exists?(slug: slug)      slug = title + "-#{n}"      n + 1    end  end  

My question is, if I perform this code before saving the record, will Friendly ID attempt to create a new slug, or simply go with the one I've manually assigned?

I've looked through the documentation and SO but can't seem to find anything.

Thanks in advance.

Ruby on rails style footer different in each page

Posted: 16 Jan 2017 08:00 AM PST

I'm using ruby on rails and I need that categories show page have footer with position: fixed; and in other pages leave position: relative;. How i can do that?

Categories show.html.erb

<div class="container">    <div id="gallery">      <h2 class="category-name"><%= @category.name %> <small class="pull-right"><%= link_to "Edit", edit_category_path %></small></h2>        <% if @images.exists? %>      <% @images.each_slice(4) do |image| %>      <div class="row">        <% image.each do |image| %>        <div class="col-md-3 col-xs-12 col-sm-6 images-column">          <div class="photo photo-type-line">            <a href="<%= image.image_url() %>" class="photo-hover img-responsive" data-lightbox="my-images" data-title="<%= image.image_title %>">              <div class="photo-info">                <div class="headline"><%= image.image_title %></div>                <div class="line"></div>                <div class="description"><%= image.image_description %></div>              </div>              <div class="mask"></div>            </a>            <div class="photo-img"><%= image_tag image.image_url(:thumb) unless image.image.blank? %></div>          </div>          <div class="share-buttons">            <span class='st_facebook' displayText='Facebook'></span>            <span class='st_twitter' displayText='Tweet'></span>            <span class='st_pinterest' displayText='Pinterest'></span>          </div>        </div>        <% end %>      </div>      <% end %>      <% else %>      <p class="no-images-attention">There are no images</p>      <% end %>    </div>  </div>  

Thank you for help!

Failed to build gem native extension - error while installing unicorn gem on Ruby 2.2.2

Posted: 16 Jan 2017 06:38 AM PST

I am getting following error while installing unicorn on Ruby 2.2.2

root@magnificent-apps:~# gem install unicorn --no-ri --no-rdoc  Building native extensions.  This could take a while...  ERROR:  Error installing unicorn:      ERROR: Failed to build gem native extension.        /usr/local/rvm/rubies/ruby-2.2.2/bin/ruby -r ./siteconf20170116-4446-95pp1l.rb extconf.rb  checking for mmap() in sys/mman.h... *** extconf.rb failed ***  Could not create Makefile due to some reason, probably lack of necessary  libraries and/or headers.  Check the mkmf.log file for more details.  You may  need configuration options.    Provided configuration options:      --with-opt-dir      --without-opt-dir      --with-opt-include      --without-opt-include=${opt-dir}/include      --with-opt-lib      --without-opt-lib=${opt-dir}/lib      --with-make-prog      --without-make-prog      --srcdir=.      --curdir      --ruby=/usr/local/rvm/rubies/ruby-2.2.2/bin/$(RUBY_BASE_NAME)      --with-atomic_ops-dir      --without-atomic_ops-dir      --with-atomic_ops-include      --without-atomic_ops-include=${atomic_ops-dir}/include      --with-atomic_ops-lib      --without-atomic_ops-lib=${atomic_ops-dir}/lib  /usr/local/rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/mkmf.rb:456:in `try_do': The compiler failed to generate an executable file. (RuntimeError)  You have to install development tools first.      from /usr/local/rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/mkmf.rb:541:in `try_link0'      from /usr/local/rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/mkmf.rb:556:in `try_link'      from /usr/local/rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/mkmf.rb:735:in `try_func'      from /usr/local/rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/mkmf.rb:1020:in `block in have_func'      from /usr/local/rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/mkmf.rb:911:in `block in checking_for'      from /usr/local/rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/mkmf.rb:351:in `block (2 levels) in postpone'      from /usr/local/rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/mkmf.rb:321:in `open'      from /usr/local/rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/mkmf.rb:351:in `block in postpone'      from /usr/local/rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/mkmf.rb:321:in `open'      from /usr/local/rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/mkmf.rb:347:in `postpone'      from /usr/local/rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/mkmf.rb:910:in `checking_for'      from /usr/local/rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/mkmf.rb:1019:in `have_func'      from extconf.rb:4:in `<main>'    extconf failed, exit code 1    Gem files will remain installed in /usr/local/rvm/gems/ruby-2.2.2/gems/raindrops-0.17.0 for inspection.  Results logged to /usr/local/rvm/gems/ruby-2.2.2/extensions/x86_64-linux/2.2.0/raindrops-0.17.0/gem_make.out  

Can anybody suggest how to fix this?

undefined method `login' for #<Employee::ActiveRecord_Relation*>

Posted: 16 Jan 2017 06:30 AM PST

I am getting below error when I try to access 'login' method of object class in views.

undefined method `login' for #<Employee::ActiveRecord_Relation:0xb2ea0800>  

This is what I write in views:

<%= form_for :employees, url: 'employees/login' do |f| %>    <%= f.text_field :login %>  <% end %>  

This is how my model look like:

class Employee < ApplicationRecord  end  

What could be the problem?

Test webcal(iCalendar) url from local server

Posted: 16 Jan 2017 06:03 AM PST

I made path in rails which generate .ics file for i calendar. How can i test that link from local server Here is how i generate .ics file on path(/api/calendar/):

  send_data cal.to_ical, filename: file_name, type: "text/calendar; charset=utf-8", disposition: 'attachment'  

Rails Simple form button id

Posted: 16 Jan 2017 06:40 AM PST

I can't get the id to work in simple form on a button, I've tried

this

= f.button, :input_html => { :id => 'my_id' }  = f.button, :input_html => { :id => 'my_id' }, :submit  

and this

= f.button, html: { id: :edit_account }   = f.button, html: { id: :edit_account } :submit  

What's the proper way of doing it?

Why do my tests not pass?

Posted: 16 Jan 2017 05:53 AM PST

I am using Michael Hartl's book to learn rails. I am covering a section about uniqueness validation. I have copied it word for word (as it seems), and it is still not passing. Any thoughts?

User.rb:

class User < ApplicationRecord      validates :name, presence: true, length: {maximum: 50}      VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i      validates :email, presence: true, length: {maximum: 255},      format: { with: VALID_EMAIL_REGEX},      uniqueness: case_sensitive: false  end  

Test/User_test.rb

require 'test_helper'    class UserTest < ActiveSupport::TestCase        def setup          @user = User.new(name: "Example User", email: "user@example.com")      end    test "email addresses should be unique" do      duplicate_user = @user.dup      duplicate_user.email = @user.email.upcase      @user.save      assert_not duplicate_user.valid?  end  

Error:

Error:

UserTest#test_name_should_be_present:  SyntaxError: /home/benjamin/Desktop/Projects/sample_app/app/models/user.rb:6: syntax error, unexpected tLABEL      uniqueness: case_sensitive: false                                 ^  

Rails I18n - Translate the same attributes multiple times for model and views?

Posted: 16 Jan 2017 05:42 AM PST

Suppose we have a Book model with index, show, edit and new views. Suppose we want to internationalize and translate all of those views and use lazy lookup (automatic translation scoping) when passing the key names to the t method in the views.

The only solution I have found so far is to include multiple keys for the same attribute in the dictionary (YML file): one key for the model (which will translate the form labels) and one additional key for each view. Example:

#pt-BR.yml  pt-BR:    activerecord:      attributes:        book:          title: Título    books:      index:        title: Título      show:        title: Título  

Given the importance attributed to the DRY principle in the Rails community, I believe there is probably a way to avoid having multiple keys for the same attribute.

One possible alternative could be to include only the activerecord keys in the dictionary (only translate the model) but it seems like lazy lookup will not work in the views. We could do something like <%= t('activerecord.attributes.book.title') %> in the views, but it does not look like a proper solution as we have to repeat the entire scope (activerecord.attributes.book) every time we call the t method.

I appreciate if anyone can point me to a way to better/DRYer way to to this. Thank you.

How to use devise to give privilege to different user?

Posted: 16 Jan 2017 06:30 AM PST

I am a teacher(admin) that create 3 different questions(posts) to 3 students(users). Each student can and only can view the post with their name on it.

How can I do it?

How to disable browser back-forward and refresh button

Posted: 16 Jan 2017 06:54 AM PST

I want to disable browser back-forward and refresh button. for taking quiz by student with Jquery.

I tried belowed code but it's not working.

window.history.forward();  function preventBack() { window.history.forward(1); }    function disableBackButton() {    window.history.forward();  }  setTimeout("disableBackButton()", 0);  

please help me thanks in advance.

How Rails render finds variable

Posted: 16 Jan 2017 05:24 AM PST

Simple example:

index.html.erb:

<% @posts.each do |post| %>   <%= post.title %>  <% end %>  

I can refactor this and move content to the _post.html.erb partial:

index.html.erb:

<%= render @posts %>  

_post.html.erb:

 <%= post.title %>  

So how Rails passes attributes of every post without creating a block? My posts_controller index action has only @posts = Post.all defined.

I thought that maybe by the name of the partial (post), but looks like its another Rails convention (plural and singular naming). Is it?

Many thanks for sharing!

Getting There is already a server bound to when trying to start Puma server

Posted: 16 Jan 2017 05:05 AM PST

I have a Rails app working on Puma and deployed by Capistrano 3. For monitoring Puma server and auto start after OS reboot I use systemd srvice. Here is a config:

[Service]  # Background process configuration (use with --daemon in ExecStart)  Type=forking    WorkingDirectory=/home/rails/current    # To learn which exact command is to be used to execute at "ExecStart" of this  # Service, ask Capistrano: `cap <stage> puma:start --dry-run`. Your result  # may differ from this example, for example if you use a Ruby version  # manager. `<WD>` is short for "your working directory". Replace it with your  # path.  ExecStart=/usr/local/rvm//bin/rvm default do bundle exec puma -C /home/rails/shared/puma.rb --daemon  # To learn which exact command is to be used to execute at "ExecStop" of this  # Service, ask Capistrano: `cap <stage> puma:stop --dry-run`. Your result  # may differ from this example, for example if you use a Ruby version  # manager. `<WD>` is short for "your working directory". Replace it with your  # path.  ExecStop=/usr/local/rvm//bin/rvm default do bundle exec pumactl -S /home/rails/shared/tmp/pids/puma.state stop  # PIDFile setting is required in order to work properly  PIDFile=/home/rails/shared/tmp/pids/puma.pid    Restart=always  [Install]  WantedBy=multi-user.target  

The problem is to restart Puma after deploy. It can't do it if server has been started by systemd. I get There is already a server bound to on deploy. Is there workaround for that?

Testing callbacks with minitest rails

Posted: 16 Jan 2017 05:03 AM PST

I have a before_validation callback in my model. I am unable to find how to write test cases for callbacks in minitest rails.

Heroku build failed

Posted: 16 Jan 2017 04:51 AM PST

I have a Rails 5 app and I'm trying to deploy it for the first time on Heroku. It gives me the following log, not sure where is the issue.

   I, [2017-01-16T12:43:13.155285 #3787]  INFO -- : Writing /tmp/build_14044c73ce6e495d61ab25d40db08259/public/assets/admin/pages/media/works/img6-d846d51b577b94b6f4ec648085738337926f2d75510b067f6bf76bcc87644a80.jpg       rake aborted!       Sass::SyntaxError: Undefined mixin 'theme'.       /tmp/build_14044c73ce6e495d61ab25d40db08259/app/assets/stylesheets/admin/global/plugins/jquery-notific8/_themes.scss:12:in `theme'       /tmp/build_14044c73ce6e495d61ab25d40db08259/app/assets/stylesheets/admin/global/plugins/jquery-notific8/_themes.scss:12       /tmp/build_14044c73ce6e495d61ab25d40db08259/vendor/bundle/ruby/2.3.0/gems/sass-3.4.23/lib/sass/tree/visitors/perform.rb:351:in `block in visit_mixin'       /tmp/build_14044c73ce6e495d61ab25d40db08259/vendor/bundle/ruby/2.3.0/gems/sass-3.4.23/lib/sass/stack.rb:98:in `block in with_mixin'       /tmp/build_14044c73ce6e495d61ab25d40db08259/vendor/bundle/ruby/2.3.0/gems/sass-3.4.23/lib/sass/stack.rb:115:in `with_frame'       /tmp/build_14044c73ce6e495d61ab25d40db08259/vendor/bundle/ruby/2.3.0/gems/sass-3.4.23/lib/sass/stack.rb:98:in `with_mixin'       /tmp/build_14044c73ce6e495d61ab25d40db08259/vendor/bundle/ruby/2.3.0/gems/sass-3.4.23/lib/sass/tree/visitors/perform.rb:349:in `visit_mixin'       /tmp/build_14044c73ce6e495d61ab25d40db08259/vendor/bundle/ruby/2.3.0/gems/sass-3.4.23/lib/sass/tree/visitors/base.rb:36:in `visit'       /tmp/build_14044c73ce6e495d61ab25d40db08259/vendor/bundle/ruby/2.3.0/gems/sass-3.4.23/lib/sass/tree/visitors/perform.rb:160:in `block in visit'       /tmp/build_14044c73ce6e495d61ab25d40db08259/vendor/bundle/ruby/2.3.0/gems/sass-3.4.23/lib/sass/stack.rb:79:in `block in with_base'       /tmp/build_14044c73ce6e495d61ab25d40db08259/vendor/bundle/ruby/2.3.0/gems/sass-3.4.23/lib/sass/stack.rb:115:in `with_frame'       /tmp/build_14044c73ce6e495d61ab25d40db08259/vendor/bundle/ruby/2.3.0/gems/sass-3.4.23/lib/sass/stack.rb:79:in `with_base'       /tmp/build_14044c73ce6e495d61ab25d40db08259/vendor/bundle/ruby/2.3.0/gems/sass-3.4.23/lib/sass/tree/visitors/perform.rb:160:in `visit'       /tmp/build_14044c73ce6e495d61ab25d40db08259/vendor/bundle/ruby/2.3.0/gems/sass-3.4.23/lib/sass/tree/visitors/base.rb:52:in `block in visit_children'       /tmp/build_14044c73ce6e495d61ab25d40db08259/vendor/bundle/ruby/2.3.0/gems/sass-3.4.23/lib/sass/tree/visitors/base.rb:52:in `map'       /tmp/build_14044c73ce6e495d61ab25d40db08259/vendor/bundle/ruby/2.3.0/gems/sass-3.4.23/lib/sass/tree/visitors/base.rb:52:in `visit_children'       /tmp/build_14044c73ce6e495d61ab25d40db08259/vendor/bundle/ruby/2.3.0/gems/sass-3.4.23/lib/sass/tree/visitors/perform.rb:169:in `block in visit_children'       /tmp/build_14044c73ce6e495d61ab25d40db08259/vendor/bundle/ruby/2.3.0/gems/sass-3.4.23/lib/sass/tree/visitors/perform.rb:181:in `with_environment'       /tmp/build_14044c73ce6e495d61ab25d40db08259/vendor/bundle/ruby/2.3.0/gems/sass-3.4.23/lib/sass/tree/visitors/perform.rb:168:in `visit_children'       /tmp/build_14044c73ce6e495d61ab25d40db08259/vendor/bundle/ruby/2.3.0/gems/sass-3.4.23/lib/sass/tree/visitors/base.rb:36:in `block in visit'       /tmp/build_14044c73ce6e495d61ab25d40db08259/vendor/bundle/ruby/2.3.0/gems/sass-3.4.23/lib/sass/tree/visitors/perform.rb:188:in `visit_root'       /tmp/build_14044c73ce6e495d61ab25d40db08259/vendor/bundle/ruby/2.3.0/gems/sass-3.4.23/lib/sass/tree/visitors/base.rb:36:in `visit'       /tmp/build_14044c73ce6e495d61ab25d40db08259/vendor/bundle/ruby/2.3.0/gems/sass-3.4.23/lib/sass/tree/visitors/perform.rb:159:in `visit'       /tmp/build_14044c73ce6e495d61ab25d40db08259/vendor/bundle/ruby/2.3.0/gems/sass-3.4.23/lib/sass/tree/visitors/perform.rb:8:in `visit'       /tmp/build_14044c73ce6e495d61ab25d40db08259/vendor/bundle/ruby/2.3.0/gems/sass-3.4.23/lib/sass/tree/root_node.rb:36:in `css_tree'       /tmp/build_14044c73ce6e495d61ab25d40db08259/vendor/bundle/ruby/2.3.0/gems/sass-3.4.23/lib/sass/tree/root_node.rb:20:in `render'       /tmp/build_14044c73ce6e495d61ab25d40db08259/vendor/bundle/ruby/2.3.0/gems/sass-3.4.23/lib/sass/engine.rb:281:in `render'       /tmp/build_14044c73ce6e495d61ab25d40db08259/vendor/bundle/ruby/2.3.0/gems/compass-rails-3.0.2/lib/compass-rails/patches/sass_importer.rb:48:in `evaluate'       /tmp/build_14044c73ce6e495d61ab25d40db08259/vendor/bundle/ruby/2.3.0/gems/tilt-2.0.5/lib/tilt/template.rb:102:in `render'       /tmp/build_14044c73ce6e495d61ab25d40db08259/vendor/bundle/ruby/2.3.0/gems/sprockets-3.7.1/lib/sprockets/legacy_tilt_processor.rb:25:in `call'       /tmp/build_14044c73ce6e495d61ab25d40db08259/vendor/bundle/ruby/2.3.0/gems/sprockets-3.7.1/lib/sprockets/processor_utils.rb:75:in `call_processor'       /tmp/build_14044c73ce6e495d61ab25d40db08259/vendor/bundle/ruby/2.3.0/gems/sprockets-3.7.1/lib/sprockets/processor_utils.rb:57:in `block in call_processors'       /tmp/build_14044c73ce6e495d61ab25d40db08259/vendor/bundle/ruby/2.3.0/gems/sprockets-3.7.1/lib/sprockets/processor_utils.rb:56:in `reverse_each'       /tmp/build_14044c73ce6e495d61ab25d40db08259/vendor/bundle/ruby/2.3.0/gems/sprockets-3.7.1/lib/sprockets/processor_utils.rb:56:in `call_processors'       /tmp/build_14044c73ce6e495d61ab25d40db08259/vendor/bundle/ruby/2.3.0/gems/sprockets-3.7.1/lib/sprockets/loader.rb:134:in `load_from_unloaded'       /tmp/build_14044c73ce6e495d61ab25d40db08259/vendor/bundle/ruby/2.3.0/gems/sprockets-3.7.1/lib/sprockets/loader.rb:60:in `block in load'       /tmp/build_14044c73ce6e495d61ab25d40db08259/vendor/bundle/ruby/2.3.0/gems/sprockets-3.7.1/lib/sprockets/loader.rb:317:in `fetch_asset_from_dependency_cache'       /tmp/build_14044c73ce6e495d61ab25d40db08259/vendor/bundle/ruby/2.3.0/gems/sprockets-3.7.1/lib/sprockets/loader.rb:44:in `load'       /tmp/build_14044c73ce6e495d61ab25d40db08259/vendor/bundle/ruby/2.3.0/gems/sprockets-3.7.1/lib/sprockets/cached_environment.rb:20:in `block in initialize'       /tmp/build_14044c73ce6e495d61ab25d40db08259/vendor/bundle/ruby/2.3.0/gems/sprockets-3.7.1/lib/sprockets/cached_environment.rb:47:in `load'       /tmp/build_14044c73ce6e495d61ab25d40db08259/vendor/bundle/ruby/2.3.0/gems/sprockets-3.7.1/lib/sprockets/bundle.rb:23:in `block in call'       /tmp/build_14044c73ce6e495d61ab25d40db08259/vendor/bundle/ruby/2.3.0/gems/sprockets-3.7.1/lib/sprockets/utils.rb:200:in `dfs'       /tmp/build_14044c73ce6e495d61ab25d40db08259/vendor/bundle/ruby/2.3.0/gems/sprockets-3.7.1/lib/sprockets/bundle.rb:24:in `call'       /tmp/build_14044c73ce6e495d61ab25d40db08259/vendor/bundle/ruby/2.3.0/gems/sprockets-3.7.1/lib/sprockets/processor_utils.rb:75:in `call_processor'       /tmp/build_14044c73ce6e495d61ab25d40db08259/vendor/bundle/ruby/2.3.0/gems/sprockets-3.7.1/lib/sprockets/processor_utils.rb:57:in `block in call_processors'       /tmp/build_14044c73ce6e495d61ab25d40db08259/vendor/bundle/ruby/2.3.0/gems/sprockets-3.7.1/lib/sprockets/processor_utils.rb:56:in `reverse_each'       /tmp/build_14044c73ce6e495d61ab25d40db08259/vendor/bundle/ruby/2.3.0/gems/sprockets-3.7.1/lib/sprockets/processor_utils.rb:56:in `call_processors'       /tmp/build_14044c73ce6e495d61ab25d40db08259/vendor/bundle/ruby/2.3.0/gems/sprockets-3.7.1/lib/sprockets/loader.rb:134:in `load_from_unloaded'       /tmp/build_14044c73ce6e495d61ab25d40db08259/vendor/bundle/ruby/2.3.0/gems/sprockets-3.7.1/lib/sprockets/loader.rb:60:in `block in load'       /tmp/build_14044c73ce6e495d61ab25d40db08259/vendor/bundle/ruby/2.3.0/gems/sprockets-3.7.1/lib/sprockets/loader.rb:317:in `fetch_asset_from_dependency_cache'       /tmp/build_14044c73ce6e495d61ab25d40db08259/vendor/bundle/ruby/2.3.0/gems/sprockets-3.7.1/lib/sprockets/loader.rb:44:in `load'       /tmp/build_14044c73ce6e495d61ab25d40db08259/vendor/bundle/ruby/2.3.0/gems/sprockets-3.7.1/lib/sprockets/cached_environment.rb:20:in `block in initialize'       /tmp/build_14044c73ce6e495d61ab25d40db08259/vendor/bundle/ruby/2.3.0/gems/sprockets-3.7.1/lib/sprockets/cached_environment.rb:47:in `load'       /tmp/build_14044c73ce6e495d61ab25d40db08259/vendor/bundle/ruby/2.3.0/gems/sprockets-3.7.1/lib/sprockets/base.rb:66:in `find_asset'       /tmp/build_14044c73ce6e495d61ab25d40db08259/vendor/bundle/ruby/2.3.0/gems/sprockets-3.7.1/lib/sprockets/base.rb:73:in `find_all_linked_assets'       /tmp/build_14044c73ce6e495d61ab25d40db08259/vendor/bundle/ruby/2.3.0/gems/sprockets-3.7.1/lib/sprockets/manifest.rb:142:in `block in find'       /tmp/build_14044c73ce6e495d61ab25d40db08259/vendor/bundle/ruby/2.3.0/gems/sprockets-3.7.1/lib/sprockets/legacy.rb:114:in `block (2 levels) in logical_paths'       /tmp/build_14044c73ce6e495d61ab25d40db08259/vendor/bundle/ruby/2.3.0/gems/sprockets-3.7.1/lib/sprockets/path_utils.rb:228:in `block in stat_tree'       /tmp/build_14044c73ce6e495d61ab25d40db08259/vendor/bundle/ruby/2.3.0/gems/sprockets-3.7.1/lib/sprockets/path_utils.rb:212:in `block in stat_directory'       /tmp/build_14044c73ce6e495d61ab25d40db08259/vendor/bundle/ruby/2.3.0/gems/sprockets-3.7.1/lib/sprockets/path_utils.rb:209:in `each'       /tmp/build_14044c73ce6e495d61ab25d40db08259/vendor/bundle/ruby/2.3.0/gems/sprockets-3.7.1/lib/sprockets/path_utils.rb:209:in `stat_directory'       /tmp/build_14044c73ce6e495d61ab25d40db08259/vendor/bundle/ruby/2.3.0/gems/sprockets-3.7.1/lib/sprockets/path_utils.rb:227:in `stat_tree'       /tmp/build_14044c73ce6e495d61ab25d40db08259/vendor/bundle/ruby/2.3.0/gems/sprockets-3.7.1/lib/sprockets/legacy.rb:105:in `each'       /tmp/build_14044c73ce6e495d61ab25d40db08259/vendor/bundle/ruby/2.3.0/gems/sprockets-3.7.1/lib/sprockets/legacy.rb:105:in `block in logical_paths'       /tmp/build_14044c73ce6e495d61ab25d40db08259/vendor/bundle/ruby/2.3.0/gems/sprockets-3.7.1/lib/sprockets/legacy.rb:104:in `each'       /tmp/build_14044c73ce6e495d61ab25d40db08259/vendor/bundle/ruby/2.3.0/gems/sprockets-3.7.1/lib/sprockets/legacy.rb:104:in `logical_paths'       /tmp/build_14044c73ce6e495d61ab25d40db08259/vendor/bundle/ruby/2.3.0/gems/sprockets-3.7.1/lib/sprockets/manifest.rb:140:in `find'       /tmp/build_14044c73ce6e495d61ab25d40db08259/vendor/bundle/ruby/2.3.0/gems/sprockets-3.7.1/lib/sprockets/manifest.rb:185:in `compile'       /tmp/build_14044c73ce6e495d61ab25d40db08259/vendor/bundle/ruby/2.3.0/gems/sprockets-rails-3.2.0/lib/sprockets/rails/task.rb:68:in `block (3 levels) in define'       /tmp/build_14044c73ce6e495d61ab25d40db08259/vendor/bundle/ruby/2.3.0/gems/sprockets-3.7.1/lib/rake/sprocketstask.rb:147:in `with_logger'       /tmp/build_14044c73ce6e495d61ab25d40db08259/vendor/bundle/ruby/2.3.0/gems/sprockets-rails-3.2.0/lib/sprockets/rails/task.rb:67:in `block (2 levels) in define'       /tmp/build_14044c73ce6e495d61ab25d40db08259/vendor/bundle/ruby/2.3.0/gems/rake-12.0.0/exe/rake:27:in `<top (required)>'       Tasks: TOP => assets:precompile       (See full trace by running task with --trace)    !    !     Precompiling assets failed.    !    !     Push rejected, failed to compile Ruby app.    !     Push failed  

Can you please help me fix it? I tried finiding 'theme' but didn't understand where to look.

How can I identify and fix this issue?

Here is the content of app/assets/stylesheets/admin/global/plugins/jquery-notific8/_themes.scss

/**   * @author Will Steinmetz   *    * Themes for the notific8 plug-in for jQuery   *    * Copyright (c)2013, Will Steinmetz   * Licensed under the BSD license.   * http://opensource.org/licenses/BSD-3-Clause   */    @include theme(teal, #09c, #069);  @include theme(amethyst, #915faa, #5D2D77);  @include theme(ruby, #d10, #a10);  @include theme(tangerine, #ffb23f, #e88f00);  @include theme(lemon, #ffde00, #ffcc00, #ffde00, #333);  @include theme(lime, #38d315, #32b512);  @include theme(ebony, #666, #121212);  @include theme(smoke, #ababab, #efefef, #ababab, #333, #fff);  

rails generates wrong 'show' route

Posted: 16 Jan 2017 04:44 AM PST

i have following show function:

def show      @article = Article.find(params[:id])  end  

my routes.rb looks like this:

resource :articles  

but when i run rake routes, i get this output:

     articles POST   /articles(.:format)      articles#create   new_articles GET    /articles/new(.:format)  articles#new  edit_articles GET    /articles/edit(.:format) articles#edit                GET    /articles(.:format)      articles#show                PATCH  /articles(.:format)      articles#update                PUT    /articles(.:format)      articles#update                DELETE /articles(.:format)      articles#destroy           root GET    /    

as you can see the articles#show route is wrong because an :id is needed to show a single article.

Query mysql table using ruby by reading filter data from file

Posted: 16 Jan 2017 04:44 AM PST

I have to run a query against a table (tableA) and fetch 10 million or so id's (varchar) and then use those id's in the WHERE clause of a different table (tableB) on a different server. I am doing this using ruby.

Here is what I currently have:

I fetch required id's from table1 using the below code and place it in a txt file:

system("#{queryToExecute} -e \"#{queryFromSource} \"> #{csvfilename}.txt")   

queryToExecute is a straight forward select statement on table1:

Sample rows from the txt file

7fa6530f-309e-435f-a64b-099514bccfb3  b408db72-2929-4121-a6fb-5589520914fb  942eb682-2ce0-4462-b773-144e9255e37c  ed3adc78-7fa3-423c-932b-b97a46b2fa07  

I then do some cleanup on the text file with results using:

system("sed '1d' #{csvfilename}.txt > #{csvfilename}_temp.txt;mv #{csvfilename}_temp.txt #{csvfilename}.txt")        system("paste -d',' -s #{csvfilename}.txt > #{csvfilename}_temp.txt;mv #{csvfilename}_temp.txt #{csvfilename}.txt")        filedata = File.read(csvfilename+".txt")        filedata =   filedata.gsub!(",","','")       filedata =   filedata.gsub!("\n","")       filedata = "'" + filedata +   "'"  @ids = filedata   

After cleanup, this is what I have in @ids:

'7fa6530f-309e-435f-a64b-099514bccfb3','b408db72-2929-4121-a6fb-5589520914fb','942eb682-2ce0-4462-b773-144e9255e37c','ed3adc78-7fa3-423c-932b-b97a46b2fa07'  

Now I substitute @ids in my new query and execute same as above. My final query looks something like this:

SELECT col1, col2 FROM Table2 WHERE ids IN #{@ids}   

The problem I am facing is when there are millions of id's to search, It does not return complete result set. However, if I limit my id's from table1 I get required results..

Since the query is huge I am not able to print and validate.

Is there a better way to do this?

How do you run migrations for a particular gem on heroku?

Posted: 16 Jan 2017 04:10 AM PST

On development environment I have build a new gem and installed it running bundle exec rails g new_gem_name:install which installs the gem's migrations

After pushing it to heroku I need to do the same thing there.

How to I run only this gem's migrations on heroku ?

How to handle routing using react-rails and react-rails-router?

Posted: 16 Jan 2017 04:40 AM PST

I have to add an extra route in my existing react-rails app. I have existing components that are rendered in my view(app/views/template1.html.slim) as follows:

= react_component 'MyComponent', { data: @data1 }  

This view is rendered in rails route(say: /route1). Now when navigating around MyComponent, I am required to add few routes. I am trying to use react-router-rails. But I am did not understand one part of the documentation:

var Route = ReactRouter.Route;    this.MyRoutes = (    <Route handler={App}>      <Route name='home' handler={Home} path='/' />      ...    </Route>   );  

What is the handler passed in the Route? And I am getting undefined reference error for MyRoutes.

How to develop web application which works offline

Posted: 16 Jan 2017 03:47 AM PST

This is not a programming question but i need some guidance actually i wanted a develop a web base application for some stores Like POS but what want that the application must a web application but it must be available for working even if the computer is not connected to the internet and when it connects than data will be synchronize automatically.

So i wanted to know the following answers.    1) Is it possible?  2) Which language should be the best for this.  3) Which framework should i use ?  

Ruby On Rails - styles not rendering properly

Posted: 16 Jan 2017 07:40 AM PST

I am migrating a frontend webpage to the rails environment. I have used the Material Design Lite library to style my form fields. I have defined two routes till now: /home and /home/new. The /home page has a link which leads to /home/new.

When using the link to go to /home/new, the floating labels in the form fields are not getting rendered. But when I directly go to /home/new by typing in the address bar, all the styles get rendered properly.

Style not getting rendered

Style getting rendered

How to fix this issue?

home\index.html.erb

 <!DOCTYPE html>  <html lang="eng">    <head>      <meta charset="UTF-8">      <meta http-equiv="X-UA-Compatible" content="IE=edge">      <meta name="viewport" content="width=device-width, initial-scale=1.0">      <title>SMS scheduling site</title>      <%= stylesheet_link_tag "home.style" %>    </head>      <body>      <h1>Saved Campaigns</h1>          <p> <%= link_to 'Create New Campaign', "/home/new" %></p>          </body>  </html>  

home/new.html.erb

<!DOCTYPE html>  <html lang="en">    <head>    <meta charset="UTF-8">    <meta http-equiv="X-UA-Compatible" content="IE=edge">    <meta name="viewport" content="width=device-width, initial-scale=1.0">    <title>SMS scheduling site</title>      <%= stylesheet_link_tag "mdDateTimePicker" %>    <%= stylesheet_link_tag "style" %>        </head>    <body>  <div class="container-div">    <!-- Colored FAB button with ripple -->    <button id="fab" class="mdl-button mdl-js-button mdl-button--fab mdl-js-ripple-effect mdl-button--colored">      <i class="material-icons">add</i>    </button>      <div class="demo-card-wide mdl-card mdl-shadow--2dp">      <div class="mdl-card__title" id="text-div">        <h2 id="title-text" class="mdl-card__title-text">CAMPAIGN</h2>        <br>        <br>        <span id="success">Success!</span>      </div>      <div class="mdl-card__supporting-text">        <form action="#">            <div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">            <input class="mdl-textfield__input" type="text" id="campaign-name">            <label class="mdl-textfield__label" for="phone-number-receiver">Campaign Name</label>          </div>            <div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">            <input class="mdl-textfield__input" type="text" pattern="-?[0-9]*(\.[0-9]+)?" id="phone-number-receiver">            <label class="mdl-textfield__label" for="phone-number-receiver">Phone Number for recipient</label>            <span class="mdl-textfield__error">Input is not a number!</span>          </div>            <div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">            <input class="mdl-textfield__input" type="text" id="start-date">            <label class="mdl-textfield__label" for="start-date" id="start-date-label">Enter start date</label>          </div>              <div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">            <input class="mdl-textfield__input" type="text"  id="end-date">            <label class="mdl-textfield__label" for="end-date" id="end-date-label">Enter end date</label>          </div>            <div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">            <input class="mdl-textfield__input" type="text"  id="start-time">            <label class="mdl-textfield__label" for="end-date" id="start-time-label">Enter time</label>          </div>            <div class="mdl-textfield mdl-js-textfield less-margin">            <textarea class="mdl-textfield__input" type="text" id="sms-msg" rows="8" columns="40"></textarea>            <label class="mdl-textfield__label" for="sms-msg">Text lines...</label>            </div>          <div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">            <input class="mdl-textfield__input" type="text"  id="break-msg" value="1">            <label class="mdl-textfield__label" for="break-msg">Number of Pages</label>          </div>        </form>      </div>    </div>  </div>        <%= javascript_include_tag "mdDateTimePicker" %>  <%= javascript_include_tag "app" %>  </body>    </html>  

routes.rb

Rails.application.routes.draw do    # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html    get '/home', to: 'home#index'    get '/home/new', to: 'home#new'  end  

application.html.erb

<!DOCTYPE html>  <html>    <head>      <title>SmsScheduler</title>      <%= csrf_meta_tags %>        <%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track': 'reload' %>      <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>        <%= stylesheet_link_tag "https://fonts.googleapis.com/icon?family=Material+Icons" %>      <%= stylesheet_link_tag "https://fonts.googleapis.com/css?family=Roboto:regular,bold,italic,thin,light,bolditalic,black,medium&amp;lang=en" %>      <%= stylesheet_link_tag "https://fonts.googleapis.com/css?family=Roboto+Mono" %>        </head>      <body>      <%= yield %>    </body>  </html>  

application.js

//= require turbolinks  //= require_tree  //= require jquery  //= require jquery-ui  //= require moment  //= require material  //= require draggabilly.pkgd  

application.css

/*  *= require_tree .   *= require_self   *= require jquery-ui   *= require material   */  

Unable to install the Nokogiri gem using Ruby 1.9.3

Posted: 16 Jan 2017 04:19 AM PST

I'm using ruby 1.9.3 on my rails (3.2.19) app and I'm unable to run bundle because nokogiri requires a Ruby version >= 2.1.0. At the moment I cannot upgrade my ruby version and I really need to install nokogiri otherwise my app won't run.

Besides the regular solutions (gem install...), I've already tried the following command line with no success.

gem install nokogiri -- --use-system-libraries=true --with-xml2-include=/usr/include/libxml2

ERROR:

Error installing nokogiri: nokogiri requires Ruby version >= 2.1.0.

Is there a way that I can install Nokogiri using my current ruby version?

Aditional Info:
Rails version - 3.2.19
Ruby version - 1.9.3
Nokogiri version - 1.7.0.1
OS - CentOS 7

Rails Minitesting to see if method calls another class's method?

Posted: 16 Jan 2017 05:11 AM PST

I have been reading stackoverflow articles and blogs all afternoon on minitest stubbing and mocking and I am still so confused on how to apply it to my situation.

  1. I have a class called "Employee" that has a class method called "register_employee".
  2. I have a second class "MessageParser" with a class method called "parse" that calls "Employee.register_employee"
  3. I want to test to make sure MessageParser.parse calls Employee.register_employee

I tried the following code:

class MessageParserTest < ActiveSupport::TestCase      mock = Minitest::Mock.new      mock.expect Employee.register_employee, nil, ["5129603333"]        Employee.stub :new, mock do           MessageParser.parse("register", "5129603333")      end  end  

But I get code saying Employee.register_employee is missing an argument (0 for 1).

Any help would be greatly appreciated!

Edit: I tried creating a method in my same class that takes one argument and it's still telling me it needs an argument even though I've got that string in brackets. So setting aside the fact I am trying to call different class methods, it's not working with calling a different method in the same class.

syntax error, unexpected keyword_end after launching Sidekiq

Posted: 16 Jan 2017 03:11 AM PST

My application uses Sidekiq and Sidekiq-Cron for background job processing.
Both Sidekiq and Sidekiq-Cron are included as gems in the global section of my Gemfile, and installed with bundle install in my application's rvm gemset.

After launching for the first time sidekiq or bundle exec sidekiq from the root of my Rails application, I received the following error message which I past and copy here for completeness:

asarluhi@home:~/workspace/fantasytennis_app (background-jobs)*$ sidekiq  2017-01-16T09:04:36.460Z 3850 TID-7pc7o INFO: Booting Sidekiq 4.2.7 with redis options {:url=>nil}  /home/asarluhi/.rvm/gems/ruby-2.3.1@fantasytennis_app_Rails5.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:477:in `load': /home/asarluhi/workspace/fantasytennis_app/app/workers/check_collections_worker.rb:10: syntax error, unexpected keyword_end, expecting end-of-input (SyntaxError)      from /home/asarluhi/.rvm/gems/ruby-2.3.1@fantasytennis_app_Rails5.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:477:in `block in load_file'      from /home/asarluhi/.rvm/gems/ruby-2.3.1@fantasytennis_app_Rails5.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:662:in `new_constants_in'      from /home/asarluhi/.rvm/gems/ruby-2.3.1@fantasytennis_app_Rails5.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:476:in `load_file'      from /home/asarluhi/.rvm/gems/ruby-2.3.1@fantasytennis_app_Rails5.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:375:in `block in require_or_load'      from /home/asarluhi/.rvm/gems/ruby-2.3.1@fantasytennis_app_Rails5.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:37:in `block in load_interlock'      from /home/asarluhi/.rvm/gems/ruby-2.3.1@fantasytennis_app_Rails5.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies/interlock.rb:12:in `block in loading'      from /home/asarluhi/.rvm/gems/ruby-2.3.1@fantasytennis_app_Rails5.0/gems/activesupport-5.0.0.1/lib/active_support/concurrency/share_lock.rb:117:in `exclusive'      from /home/asarluhi/.rvm/gems/ruby-2.3.1@fantasytennis_app_Rails5.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies/interlock.rb:11:in `loading'      from /home/asarluhi/.rvm/gems/ruby-2.3.1@fantasytennis_app_Rails5.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:37:in `load_interlock'      from /home/asarluhi/.rvm/gems/ruby-2.3.1@fantasytennis_app_Rails5.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:358:in `require_or_load'      from /home/asarluhi/.rvm/gems/ruby-2.3.1@fantasytennis_app_Rails5.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:511:in `load_missing_constant'      from /home/asarluhi/.rvm/gems/ruby-2.3.1@fantasytennis_app_Rails5.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:203:in `const_missing'      from /home/asarluhi/.rvm/gems/ruby-2.3.1@fantasytennis_app_Rails5.0/gems/activesupport-5.0.0.1/lib/active_support/inflector/methods.rb:268:in `const_get'      from /home/asarluhi/.rvm/gems/ruby-2.3.1@fantasytennis_app_Rails5.0/gems/activesupport-5.0.0.1/lib/active_support/inflector/methods.rb:268:in `block in constantize'      from /home/asarluhi/.rvm/gems/ruby-2.3.1@fantasytennis_app_Rails5.0/gems/activesupport-5.0.0.1/lib/active_support/inflector/methods.rb:266:in `each'      from /home/asarluhi/.rvm/gems/ruby-2.3.1@fantasytennis_app_Rails5.0/gems/activesupport-5.0.0.1/lib/active_support/inflector/methods.rb:266:in `inject'      from /home/asarluhi/.rvm/gems/ruby-2.3.1@fantasytennis_app_Rails5.0/gems/activesupport-5.0.0.1/lib/active_support/inflector/methods.rb:266:in `constantize'      from /home/asarluhi/.rvm/gems/ruby-2.3.1@fantasytennis_app_Rails5.0/gems/activesupport-5.0.0.1/lib/active_support/core_ext/string/inflections.rb:66:in `constantize'      from /home/asarluhi/.rvm/gems/ruby-2.3.1@fantasytennis_app_Rails5.0/gems/sidekiq-cron-0.4.5/lib/sidekiq/cron/job.rb:304:in `initialize'      from /home/asarluhi/.rvm/gems/ruby-2.3.1@fantasytennis_app_Rails5.0/gems/sidekiq-cron-0.4.5/lib/sidekiq/cron/job.rb:186:in `new'      from /home/asarluhi/.rvm/gems/ruby-2.3.1@fantasytennis_app_Rails5.0/gems/sidekiq-cron-0.4.5/lib/sidekiq/cron/job.rb:186:in `block in load_from_array'      from /home/asarluhi/.rvm/gems/ruby-2.3.1@fantasytennis_app_Rails5.0/gems/sidekiq-cron-0.4.5/lib/sidekiq/cron/job.rb:185:in `each'      from /home/asarluhi/.rvm/gems/ruby-2.3.1@fantasytennis_app_Rails5.0/gems/sidekiq-cron-0.4.5/lib/sidekiq/cron/job.rb:185:in `load_from_array'      from /home/asarluhi/.rvm/gems/ruby-2.3.1@fantasytennis_app_Rails5.0/gems/sidekiq-cron-0.4.5/lib/sidekiq/cron/job.rb:156:in `load_from_hash'      from /home/asarluhi/workspace/fantasytennis_app/config/initializers/sidekiq.rb:5:in `block in <top (required)>'      from /home/asarluhi/.rvm/gems/ruby-2.3.1@fantasytennis_app_Rails5.0/gems/sidekiq-4.2.7/lib/sidekiq.rb:73:in `configure_server'      from /home/asarluhi/workspace/fantasytennis_app/config/initializers/sidekiq.rb:1:in `<top (required)>'      from /home/asarluhi/.rvm/gems/ruby-2.3.1@fantasytennis_app_Rails5.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:287:in `load'      from /home/asarluhi/.rvm/gems/ruby-2.3.1@fantasytennis_app_Rails5.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:287:in `block in load'      from /home/asarluhi/.rvm/gems/ruby-2.3.1@fantasytennis_app_Rails5.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:259:in `load_dependency'      from /home/asarluhi/.rvm/gems/ruby-2.3.1@fantasytennis_app_Rails5.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:287:in `load'      from /home/asarluhi/.rvm/gems/ruby-2.3.1@fantasytennis_app_Rails5.0/gems/railties-5.0.0.1/lib/rails/engine.rb:648:in `block in load_config_initializer'      from /home/asarluhi/.rvm/gems/ruby-2.3.1@fantasytennis_app_Rails5.0/gems/activesupport-5.0.0.1/lib/active_support/notifications.rb:166:in `instrument'      from /home/asarluhi/.rvm/gems/ruby-2.3.1@fantasytennis_app_Rails5.0/gems/railties-5.0.0.1/lib/rails/engine.rb:647:in `load_config_initializer'      from /home/asarluhi/.rvm/gems/ruby-2.3.1@fantasytennis_app_Rails5.0/gems/railties-5.0.0.1/lib/rails/engine.rb:612:in `block (2 levels) in <class:Engine>'      from /home/asarluhi/.rvm/gems/ruby-2.3.1@fantasytennis_app_Rails5.0/gems/railties-5.0.0.1/lib/rails/engine.rb:611:in `each'      from /home/asarluhi/.rvm/gems/ruby-2.3.1@fantasytennis_app_Rails5.0/gems/railties-5.0.0.1/lib/rails/engine.rb:611:in `block in <class:Engine>'      from /home/asarluhi/.rvm/gems/ruby-2.3.1@fantasytennis_app_Rails5.0/gems/railties-5.0.0.1/lib/rails/initializable.rb:30:in `instance_exec'      from /home/asarluhi/.rvm/gems/ruby-2.3.1@fantasytennis_app_Rails5.0/gems/railties-5.0.0.1/lib/rails/initializable.rb:30:in `run'      from /home/asarluhi/.rvm/gems/ruby-2.3.1@fantasytennis_app_Rails5.0/gems/railties-5.0.0.1/lib/rails/initializable.rb:55:in `block in run_initializers'      from /home/asarluhi/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:228:in `block in tsort_each'      from /home/asarluhi/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'      from /home/asarluhi/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:422:in `block (2 levels) in each_strongly_connected_component_from'      from /home/asarluhi/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:431:in `each_strongly_connected_component_from'      from /home/asarluhi/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:421:in `block in each_strongly_connected_component_from'      from /home/asarluhi/.rvm/gems/ruby-2.3.1@fantasytennis_app_Rails5.0/gems/railties-5.0.0.1/lib/rails/initializable.rb:44:in `each'      from /home/asarluhi/.rvm/gems/ruby-2.3.1@fantasytennis_app_Rails5.0/gems/railties-5.0.0.1/lib/rails/initializable.rb:44:in `tsort_each_child'      from /home/asarluhi/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:415:in `call'      from /home/asarluhi/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:415:in `each_strongly_connected_component_from'      from /home/asarluhi/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:349:in `block in each_strongly_connected_component'      from /home/asarluhi/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:347:in `each'      from /home/asarluhi/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:347:in `call'      from /home/asarluhi/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:347:in `each_strongly_connected_component'      from /home/asarluhi/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:226:in `tsort_each'      from /home/asarluhi/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/tsort.rb:205:in `tsort_each'      from /home/asarluhi/.rvm/gems/ruby-2.3.1@fantasytennis_app_Rails5.0/gems/railties-5.0.0.1/lib/rails/initializable.rb:54:in `run_initializers'      from /home/asarluhi/.rvm/gems/ruby-2.3.1@fantasytennis_app_Rails5.0/gems/railties-5.0.0.1/lib/rails/application.rb:352:in `initialize!'      from /home/asarluhi/workspace/fantasytennis_app/config/environment.rb:5:in `<top (required)>'      from /home/asarluhi/.rvm/gems/ruby-2.3.1@fantasytennis_app_Rails5.0/gems/sidekiq-4.2.7/lib/sidekiq/cli.rb:244:in `require'      from /home/asarluhi/.rvm/gems/ruby-2.3.1@fantasytennis_app_Rails5.0/gems/sidekiq-4.2.7/lib/sidekiq/cli.rb:244:in `boot_system'      from /home/asarluhi/.rvm/gems/ruby-2.3.1@fantasytennis_app_Rails5.0/gems/sidekiq-4.2.7/lib/sidekiq/cli.rb:50:in `run'      from /home/asarluhi/.rvm/gems/ruby-2.3.1@fantasytennis_app_Rails5.0/gems/sidekiq-4.2.7/bin/sidekiq:12:in `<top (required)>'      from /home/asarluhi/.rvm/gems/ruby-2.3.1@fantasytennis_app_Rails5.0/bin/sidekiq:23:in `load'      from /home/asarluhi/.rvm/gems/ruby-2.3.1@fantasytennis_app_Rails5.0/bin/sidekiq:23:in `<main>'      from /home/asarluhi/.rvm/gems/ruby-2.3.1@fantasytennis_app_Rails5.0/bin/ruby_executable_hooks:15:in `eval'      from /home/asarluhi/.rvm/gems/ruby-2.3.1@fantasytennis_app_Rails5.0/bin/ruby_executable_hooks:15:in `<main>'  

I checked my app/workers/check_collections_worker.rb file, which raises the "unexpected keyword_end" syntax error in line 3 of the above code, but there are no errors, as you can see:

Class CheckCollectionsWorker      include Sidekiq::Worker        def perform          collections = TennisCollection.all          collections.each do |collection|              collection.update_attribute(:check, false)          end      end  end  

Sidekiq loads its jobs from top to bottom of a list contained in config/schedule.yml. The CheckCollectionsWorker class, being at the top, is loaded first.
I tried to move to the top in turn each of the jobs inside config/schedule.yml, but for any of them I keep receiving the same "unexpected keyword_end" error message. I am sure my code is correct. The "unexpected keyword_end" reported by sderr should be where (and as) it is.

Below is an extract of config/schedule.yml concerning the collection job:

collection_job:    cron: "0 20 * 1-11 1"    class: "CheckCollectionsWorker"    queue: critical  

I copied and pasted config/initializers/sidekiq.rb from the Sidekiq-Cron GitHub page:

Sidekiq.configure_server do |config|    schedule_file = "config/schedule.yml"      if File.exists?(schedule_file)      Sidekiq::Cron::Job.load_from_hash YAML.load_file(schedule_file)    end  end  

The content of my config/sidekiq.yml file is below:

---  development:    :concurrency: 5  production:    :concurrency: 25  :queues:    - [critical, 2]    - default  

I honestly have no idea about the source of this issue, since I checked many times the code inside my workers and found no errors.

VS Code ripper-tags extension not generating ctag file

Posted: 16 Jan 2017 02:56 AM PST

Visual Studio Code extension to use CTAGS through ripper-tags is not generating a ctag file:

Error on generate tags:'C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/ripper-tags-0.3.4/lib/ripper-tags' is not recognized as an internal or external command  

The settings.json file:

// settings.json  {  "ctags": {      "executePath": "C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/ripper-tags-0.3.4/lib/ripper-tags",      "options": "--tag-file=.tags --recursive --force --exclude=/assets/ --exclude=.bundle --exclude=.git/ --exclude=coverage/ --exclude=.arcanist-extensions/ --exclude=log/ --exclude=tmp/ --exclude=bin/",      "fileName": ".tags"  }  }  

Rails Create If Two column are same otherwise update the timestamps

Posted: 16 Jan 2017 04:14 AM PST

I am working on action cable notifications on rails . Suppose i have a notification table like this

Notification Table

id    recipient_id   actor_id  type  1     1               2         Post  2     1               3         Comments  3     1               3         Folow  

I just want that whenever the notification is created dont allow the notification which have these three column same. And if there is same column just update updated at timestamps.

I seems like business logic to me . So i guess we can handle this from MODEL.

I tried validating but that will not allow me to update, isn't it? So how can i accomplish it.

So how do i check if three column exist and although it exist just update its touch column

Filtering categories

Posted: 16 Jan 2017 03:18 AM PST

In my app I have a list of providers, and each provider has categories. My models look as follows:

class Categorization < ApplicationRecord    belongs_to :category    belongs_to :provider  end    class Category < ApplicationRecord    has_many :categorizations    has_many :providers, through: :categorizations    accepts_nested_attributes_for :categorizations  end    class Provider < ApplicationRecord    has_many :categorizations    has_many :categories, through: :categorizations    accepts_nested_attributes_for :categorizations  end  

In a view, I have 2 ul lists. The first one is a list with providers, and the second one - a list of categories. It looks like:

<ul class="nav nav-justified nav-carousel upper-thumbs">      <% Provider.order(created_at: :asc).take(6).each_with_index do |provider, index| %>        <li id="<%= provider.name %>_<%= index + 1 %>" class="btn-up"><a data-href="#"><%= provider.name %></a></li>      <% end %>  </ul>    <ul id="parent" class="nav nav-justified nav-carousel left-thumbs">      <% Category.order(created_at: :asc).take(7).each_with_index do |category, index| %>        <li id="aside_<%= index + 1 %>" class="btn-aside"><i class="category_image" style="background: url(<%= category.cat_image %>) no-repeat;"></i><a data-href="#"><%= category.name %></a></li>      <% end %>  </ul>  

When I had no rails implementation, when I clicked on the provider (it was hardcoded, as well, as the categories), I could see, the categories were filtered. It was made by js:

var $btns = $('.btn-up').click(function () {        if(this.id == 'a') {            $('#parent > li#aside_1').fadeIn(450);            $('#parent > li').not($('#parent > li#aside_1')).hide();        } else {            var $el = $('.' + this.id).fadeIn(450);            $('#parent > li').not($el).hide();        }        $btns.removeClass('active');        $(this).addClass('active');    })  

So,the question is how to make the filter work, so when I click on a provider, it will show me only the categories, which belongs to that provider? Thanks.

No comments:

Post a Comment