Tuesday, November 8, 2016

cannot deploy multiple hosts in capistrano | Fixed issues

cannot deploy multiple hosts in capistrano | Fixed issues


cannot deploy multiple hosts in capistrano

Posted: 08 Nov 2016 07:37 AM PST

I'm using capistrano to deploy rails app to about 20 servers, it works ok when server num ~ 10, when increase it to >~ 10, it doesnt work anymore

Here is the error

(Backtrace restricted to imported tasks)  cap aborted!  Errno::EPIPE: Broken pipe    Tasks: TOP => git:check => git:wrapper  (See full trace by running task with --trace)  The deploy has failed with an error: Broken pipe      ** DEPLOY FAILED  ** Refer to log/capistrano.log for details. Here are the last 20 lines:        INFO [f9138121] Finished in 0.062 seconds with exit status 0 (successful).      INFO [3cffa1b4] Running /usr/bin/env chmod 700 /tmp/git-ssh-nenga-onepiece-production-khiem-nguyen.sh on onepiece-web01     DEBUG [3cffa1b4] Command: ( export RBENV_ROOT="$HOME/.rbenv/bin/rbenv" PATH="$HOME/.rbenv/shims:$HOME/.rbenv/bin:$PATH" ; /usr/bin/env chmod 700 /tmp/git-ssh-nenga-onepiece-production-khiem-nguyen.sh )     DEBUG Uploading /tmp/git-ssh-nenga-onepiece-production-khiem-nguyen.sh 0.0%      INFO [529370ca] Finished in 0.060 seconds with exit status 0 (successful).      INFO [0338770a] Running /usr/bin/env chmod 700 /tmp/git-ssh-nenga-onepiece-production-khiem-nguyen.sh on onepiece-web10     DEBUG [0338770a] Command: ( export RBENV_ROOT="$HOME/.rbenv/bin/rbenv" PATH="$HOME/.rbenv/shims:$HOME/.rbenv/bin:$PATH" ; /usr/bin/env chmod 700 /tmp/git-ssh-nenga-onepiece-production-khiem-nguyen.sh )      INFO [df72de99] Running /usr/bin/env chmod 700 /tmp/git-ssh-nenga-onepiece-production-khiem-nguyen.sh on onepiece-web12     DEBUG [df72de99] Command: ( export RBENV_ROOT="$HOME/.rbenv/bin/rbenv" PATH="$HOME/.rbenv/shims:$HOME/.rbenv/bin:$PATH" ; /usr/bin/env chmod 700 /tmp/git-ssh-nenga-onepiece-production-khiem-nguyen.sh )      INFO [066f74d9] Finished in 0.063 seconds with exit status 0 (successful).      INFO Uploading /tmp/git-ssh-nenga-onepiece-production-khiem-nguyen.sh 100.0%      INFO [436f9bd8] Running /usr/bin/env chmod 700 /tmp/git-ssh-nenga-onepiece-production-khiem-nguyen.sh on onepiece-web02     DEBUG [436f9bd8] Command: ( export RBENV_ROOT="$HOME/.rbenv/bin/rbenv" PATH="$HOME/.rbenv/shims:$HOME/.rbenv/bin:$PATH" ; /usr/bin/env chmod 700 /tmp/git-ssh-nenga-onepiece-production-khiem-nguyen.sh )      INFO [3cffa1b4] Finished in 0.065 seconds with exit status 0 (successful).      INFO [0338770a] Finished in 0.057 seconds with exit status 0 (successful).      INFO [750c08da] Running /usr/bin/env chmod 700 /tmp/git-ssh-nenga-onepiece-production-khiem-nguyen.sh on onepiece-web03     DEBUG [750c08da] Command: ( export RBENV_ROOT="$HOME/.rbenv/bin/rbenv" PATH="$HOME/.rbenv/shims:$HOME/.rbenv/bin:$PATH" ; /usr/bin/env chmod 700 /tmp/git-ssh-nenga-onepiece-production-khiem-nguyen.sh )      INFO [df72de99] Finished in 0.063 seconds with exit status 0 (successful).      INFO [436f9bd8] Finished in 0.061 seconds with exit status 0 (successful).      INFO [750c08da] Finished in 0.069 seconds with exit status 0 (successful).  

I think there's something related to ssh max connection???

How to include data-zoom-image in my image_tag on ruby rails 4.3.4

Posted: 08 Nov 2016 07:36 AM PST

I am trying to get my images to zoom in on my website.

I have added

gem 'elevatezoom-rails'  

to my GEMFILE,

I have also added

$("#zoom_01").elevateZoom();  

to my application.js file

I am just abit confused due to being a new use on where to add data-zoom-image="images/large/image1.jpg

In the code below:

  <div class="sub-title">       <% if not @product.img_url.blank? %>        <%= link_to (image_tag @product.img_url, size: "200x250")            products_path, :title => 'return to "all" products ...' %>       <% else %>        <%= image_tag "no-image.jpg", :size => "200x250" %>      <% end %>    </div>   

Carousel in bootstrap modal in rails app

Posted: 08 Nov 2016 07:35 AM PST

I'm trying to let product images appear in a carousel in a modal window.

I'm only able to see the first image. At the moment they are three for this product.

I have tried else elsif and index ==1for the else. I have also tried other modification of in the code below. I'm kind of stuck, can anyone take a look at this and advise me?

<div class="container text-center">     <h1> Click Me </h1>    <!-- Large modal -->    <button class="btn btn-default" data-toggle="modal" data-target=".bs-example-modal-lg">Large modal</button>     <div class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">   <div class="modal-dialog modal-lg">   <div class="modal-content">   <div id="carousel-example-generic" class="carousel slide" data-ride="carousel">    <!-- Wrapper for slides -->   <% @product.photos.each_with_index do |photo, index| %>     <div class="carousel-inner">       <% if index == 0 %>         <div class="item active">           <%= image_tag(photo.image.url(:large), class: 'img-responsive') %>           </div>       <% else index == 1 %>         <div class="item">          <%= image_tag(photo.image.url(:large), class: 'img-responsive') %>          </div>       <% end %>     </div>   <% end %>         <!-- Controls -->    <a class="left carousel-control" href="#carousel-example-generic" role="button" data-slide="prev">    <span class="glyphicon glyphicon-chevron-left"></span>    </a>    <a class="right carousel-control" href="#carousel-example-generic" role="button" data-slide="next">    <span class="glyphicon glyphicon-chevron-right"></span>    </a>  </div>  </div>  </div>  </div>  </div>  

Value of cookies variable is not passing in another controller when using Safari in Rails

Posted: 08 Nov 2016 07:29 AM PST

I am trying to set a cookies variable in users controller like cookies[:uuid] = user.uuid and then passing this to home controller like @a = cookies[:uuid] The value of cookies[:uuid] is getting passed in chrome but not in safari browser. I checked in logs when using safari value of cookies:[uuid] is nil. Why is this happening? Am I missing something?

Selecting the first flash message in Rails

Posted: 08 Nov 2016 07:34 AM PST

I only want to grab the first flash message. I have to send this message to an object. So far I have

flash.first.last if flash.present? and flash.first.present?  

In some cases the flash doesn't exist at all so I have to first check that it exists, then see if it has a message. I honestly don't like it. Does the FlashHash or Rails have a method that does this behavior out-of-the-box? Is there a cleaner way to do this? Thanks.

Passenger Nginx proxy_pass

Posted: 08 Nov 2016 07:20 AM PST

I have one landing page and rails app with Passenger+Nginx. I am trying to do something like this:

server {    listen 80;    server_name example.com;        if ( $remote_addr ~* ip-address-here ) {          root /home/app/public;         # Turn on Passenger       passenger_enabled on;       passenger_ruby /usr/local/rvm/gems/ruby-2.2.4@global/wrappers/ruby;      }        #else proxy_pass http://landing_page_ip;  }  

Rails render_to_string

Posted: 08 Nov 2016 07:16 AM PST

I am having difficulty with the rails render_to_string function. I have created an app using the --api flag, so i think this may be the issue as i have tested in 'full' rails apps.

Essentially i am calling:

body_html = render_to_string(template: 'reservations/print')  

which should return the html for that template. The filename is print.html.erb and just has basic data.

When i output the body_html it is empty.

I referenced this SO question What is the correct way to render_to_string in wicked pdf? and am also going to use Wicked PDF to generate a pdf file.

Many thanks

how to insert multiple values into enum column?

Posted: 08 Nov 2016 07:21 AM PST

I am trying to insert multiple values into a POSTGREs of type enum

CREATE TYPE action SET ENUM ('create', 'read', 'update','delete','CRUD');  INSERT INTO permissions(user_role_id,resource_id,scope,actions) values(401,301,'individual','read,update')  

I tried inserting data but it didn't work, how do i insert multiple enum values in postgres

Pass query result from rails controller to javascript

Posted: 08 Nov 2016 07:18 AM PST

I have a project which is based on ruby on rails and js in front end.In one of the controller I get the query result @sites which consists of many rows like id amount NewYork 200 Seattle 10000 Toronto 30 ... ....

Now I want to pass this arrays of objects to the front end which is js.In the javascript, I want to get the amount of every id.So what should I do? To make it in json? Or pass it by html? Thanks so much.

Stop the auto-indenting of ERB tags in Adobe Brackets

Posted: 08 Nov 2016 07:06 AM PST

When using ERB in Brackets the auto-indenting is incredibly frustrating. It tends to un-indent lines that contain ERB tags as if it doesn't recognise them as part of the hierarchy. Sometimes I'll indent it to the right place and then as I'm changing a piece of code in the middle of the line Brackets will un-indent the whole line.

Is there an extension that specifically tackles this problem? Is there a custom setting I could use to alter it myself?

From which directory run cap production deploy?

Posted: 08 Nov 2016 07:05 AM PST

I want update site.

I connect with ssh with remote server.

Next I go to deploy@211449-2: cd apps/name_app

I run cap production deploy, display error: -bash: cap: command not found

From which directory need I run command cap production deploy?

Can i use something like Model.find(params[:id]) in a model.rb file? - Rails 4

Posted: 08 Nov 2016 07:18 AM PST

Could one kindly advise me how one defines the below code in the controller file in a model.rb file

events_controller.rb  event = Event.find(params[:id])  

how would one write the code event = Event.find(params[:id]) in a user.rb file?

i am unsure: i tried the below in the user.rb model file but no success:

def access?      event = Event.find(params[:event_id])      self.email == event.user.email    end  

Simple_form Radiobuttons with Images

Posted: 08 Nov 2016 05:50 AM PST

I've got a collection of radiobuttons:

f.input :model, label: 'Choose One', collection: [...], as: :radio_buttons  

Now how can I add a different Picture to each of them?

Activerecord group/order by existing array

Posted: 08 Nov 2016 05:40 AM PST

My db schema

  1. User (id,name etc)
  2. video-stream (Id ,UserId, viewerCount) - one-to-one (a user can have one video stream)
  3. Followed_streams (userId,streamId) - Many to many table (a user can follow many streams and streams can be followed by multiple users)

My /streams url currently has the below way to sort the data recieved from mysql

@streams = Stream.order(viewers: :desc).page(params[:page]).per_page(16)  

Basically, the results are currently being sorted by viewer count

I want to add a function which sorts the initial table by showing followed streams first so that the followed streams always show up in the first result.

I have the below which gives me an array of all streamids that the user has followed by this

@followed_streams = Followed_streams.where('user_id': @user.id)  

is there a way i can cross-reference @followed_streams with the initial Stream table and sort the followed ids to the top?

i want to install Thrift 0.9.3 and Run it

Posted: 08 Nov 2016 05:27 AM PST

writing Thrift --version gives me Thrift version 1.0.0-dev and not Thrift version 0.9.3 althougt it was giving 0.9.3 at first Can any one help, and what is the different between them

Carrierwave - Multiple images upload too slow when adding or removing images

Posted: 08 Nov 2016 05:25 AM PST

I'm following this article in CarrierWave Wiki https://github.com/carrierwaveuploader/carrierwave/wiki/How-to%3A-Add-more-files-and-remove-single-file-when-using-default-multiple-file-uploads-feature to implement adding more images and removing images for a model in my system using CarrierWave Multiple Uploads feature.

The main code in that article is

def add_more_images(new_images)    images = @gallery.images     images += new_images    @gallery.images = images  end    def remove_image_at_index(index)    remain_images = @gallery.images # copy the array    deleted_image = remain_images.delete_at(index) # delete the target image    deleted_image.try(:remove!) # delete image from S3    @gallery.images = remain_images # re-assign back  end  

It works. However, it is too slooooow. I have looked at the log and the overall processing time is as follow:

  1. Upload 1 image: it takes 5000ms for example
  2. Add 1 more image: it takes 8500ms (2 images)
  3. Add 1 more image: it takes 12000ms (3 images)
  4. Remove 1 image: it takes 8400ms (back to 2 images)

I have tested the sample app of this solution written by the author on my local machine and it was very slow too.

It seems like CarrierWave reuploads and re-processes all images even we only add or remove 1 image. I think because we are re-assigning back new array of images to @gallery so that it treats old images as new ones.

Also there is a related issue here https://github.com/carrierwaveuploader/carrierwave/issues/1704#issuecomment-259106600

Does anyone have any better solution for adding and removing images using CarrierWave multiple upload feature?

Thanks.

MDL drawer does not fill the height of the page?

Posted: 08 Nov 2016 05:14 AM PST

I'm using Material Design Lite to add a fixed header and drawer to my Ruby on Rails app. As you can see in this video, when I navigate to another page, the drawer menu on the left hand side of the page does not fill the height of the page.

It remains at the abnormal height (even when I click another link) until I refresh the page. Can anyone figure out what's going on here? Here is the body of my application view:

<!-- Material design fixed header and drawer -->  <div class="mdl-layout mdl-js-layout mdl-layout--fixed-drawer              mdl-layout--fixed-header">    <header class="mdl-layout__header">      <div class="mdl-layout__header-row">          <!-- Add spacer to align search bar to the right -->        <div class="mdl-layout-spacer"></div>          <!-- Search bar -->        <div class="mdl-textfield mdl-js-textfield mdl-textfield--expandable                    mdl-textfield--floating-label mdl-textfield--align-right">          <label class="mdl-button mdl-js-button mdl-button--icon"                 for="fixed-header-drawer-exp">            <i class="material-icons">search</i>          </label>          <div class="mdl-textfield__expandable-holder">            <input class="mdl-textfield__input" type="text" name="sample"                   id="fixed-header-drawer-exp">          </div>        </div>        </div>    </header>      <!-- Drawer menu  -->    <div class="mdl-layout__drawer">      <span class="mdl-layout-title"></span>      <nav class="mdl-navigation">        <a class="mdl-navigation__link" href="<%= songs_path %>">Home</a>        <a class="mdl-navigation__link" href="<%= new_song_path %>">Upload</a>        <a class="mdl-navigation__link" href="">About</a>      </nav>    </div>      <!-- Page content -->    <main class="mdl-layout__content">      <div class="page-content"><%= yield %></div>    </main>  </div>  

Thanks everyone!

How to render patial through replaceWith()

Posted: 08 Nov 2016 07:04 AM PST

I have looked at similar question and the answers didn't work and may be dated. I think there used to be a thing called RJS to do this but, I am trying to simply remove one partial and replace another.

$("#me")    .replaceWith( '<%= escape_javascript render(partial: "photoSpread") %>')  

What happens is the its sent to the browser as text and just displays <%= escape_javascript render(partial: "photoSpread") %>

wicked_pdf stopped generating pdf files with the correct data

Posted: 08 Nov 2016 05:02 AM PST

After updating to rails 5, trying to generate an invoice gave me pdf files with the RoR code written in the template.

enter image description here

How to notify a user after background task is finished?

Posted: 08 Nov 2016 05:19 AM PST

I use rails with ActiveJob and sidekiq as backend. When user come on a page sidekiq create a long-term background task, how can I notice a user (by render partial on the web page) when a task would be completed?

Rails and sidekiq work as different processes. This fact confused me I don't understand how to handle completed status using background job.

Rails/RSpec: 'Travel' time helper is not available in feature specs?

Posted: 08 Nov 2016 04:46 AM PST

I just tried to use Rails' time helper method travel in one of my feature specs:

scenario 'published_at allows to set a publishing date in the future' do    magazine_article.update_attribute(:published_at, Time.now + 1.day)    expect { visit magazine_article_path(magazine_article.magazine_category, magazine_article) }           .to raise_error(ActiveRecord::RecordNotFound)      travel 2.days do      visit magazine_article_path(magazine_article.magazine_category, magazine_article)      expect(page).to have_content('Super awesome article')    end  end   

It's giving me this:

NoMethodError:     undefined method `travel' for #<RSpec::ExampleGroups::MagazineArticles::AsUser::Viewing:0x007f84a7a95640>  

What am I missing?

http://api.rubyonrails.org/classes/ActiveSupport/Testing/TimeHelpers.html

HTML in url to on Rails

Posted: 08 Nov 2016 07:16 AM PST

I want to have a link with HTML content in Rails 5 but it's seems that my code doesn't work:

<%= link_to "<i class="fa fa-dashboard"></i> <span>Dashboard</span>  <span class="pull-right-container">  <i class="fa fa-angle-left pull-right"></i>  </span>".html_safe, admin %>  

I've got a SyntaxError in Admin::IndexController#index I want to go to my admin/index controller with index action...

Thanks.

What is the meaning of <%%= in Ruby on Rails?

Posted: 08 Nov 2016 05:08 AM PST

I cannot find it anywhere but in the project I am working with. It doesn't work in the same way as <%= (I tried to change), but I can't understand the difference.

<span class="option-content" placeholder="<%=t('pages.edit.option')%>">    <%%= content %>  </span>  

Flash Notice Alert dismissable bootstrap and rails -- Cannot Delete flash notice

Posted: 08 Nov 2016 04:27 AM PST

I am using an emailer with ruby on raiils and it has a flash notice on completion. I cannot seem to delete the bootstrap flash notice when I Press the x button listed next to the flash notice. I have tried jquery.

Whenever I put the class close on the button. the button does not even show up to even be clicked. Here is some of my code. This is my create.html.erb

<div>    <% flash.each do |key, value| %>      <div class="alert-dismissible flash_notice" role="alert">       <button type="button"  data-dismiss="alert" aria-label="Close">xxx<span aria-hidden="true">&times;</span></button>          <%= value %>      </div>    <% end %>  </div>  

This is my contact controller that emails me from a contact me form and renders the flash notice

class ContactsController < ApplicationController    def new      @contact = Contact.new    end      def create      @contact = Contact.new(params[:contact])      @contact.request = request      if @contact.deliver        flash.now[:notice] = 'Thank you for your message. We will contact you soon!'      else        flash.now[:error] = 'Cannot send message.'        render :new      end    end  end  

Here is some of my application.js code... it is messy and I have tried all of the following and left them all up to show you what I have done so far in my attempts.

//= require jquery  //= require jquery_ujs  //= require turbolinks  //= require bootstrap-sprockets  //= require_tree .      $('.delete_notice').click(function() {       $('.alert-dismissible').hide();  });    $('.delete_notice').click(function() {       $('.alert-dismissible').close();  });    $('.delete_notice').click(function() {       $('.flash_notice').hide();  });    $('.delete_notice').click(function() {       $('.delete_notice').close();  });  

Encoding JWT key for APNS using rails RPUSH gem

Posted: 08 Nov 2016 05:42 AM PST

I want to use JWT key to send push notifications

I searched for libraries implementing JWT token standard: https://jwt.io/

So I found ruby-jwt gem: https://github.com/jwt/ruby-jwt

But it seems that it can't create key with the structure required by Apple:

{      "alg": "ES256",      "kid": "ABC123DEFG"  }  {      "iss": "DEF123GHIJ",      "iat": 1437179036   }  

Also, how should I use APNs Auth Key (.p8 mime-type) to generate JWT token?

Any advices are welcome

UPDATE

Ok, I found out, that it is possible to add custom fields to header https://github.com/jwt/ruby-jwt/pull/8/files

Anyways, how should I use APNs Auth Key? Does rpush gem supports jwt tokens?

Capistrano linked_dirs doubles end of path

Posted: 08 Nov 2016 04:09 AM PST

I recently upgraded to rails 5 and capistrano 3.5.

Now im facing the issue, that every folder in :linked_dirs gets double-symlinked:

In my deploy.rb

set :linked_dirs, fetch(:linked_dirs, []).push('log', 'tmp/pids',      'tmp/cache', 'tmp/sockets', 'vendor/bundle', 'public/system', 'public/uploads')  

This results in:

✔ 02 user@example.com 0.023s  ✔ 04 user@example.com 0.023s    05 ln -s /var/www/app-dir/shared/tmp/cache /var/www/app-dir/releases/20161108113840/tmp/cache  ✔ 05 user@example.com 0.025s    05 ln:    05 failed to create symbolic link '/var/www/app-dir/releases/20161108113840/tmp/cache/cache'    05 : File exists  

It searched the documentation, stack overflow and github issues for hours now..

The behaviour is the same for: append :linked_dirs, "log", "tmp/pids", "tmp/cache" ...

  • I tried capistrano 3.4, 3.5
  • I removed the whole app-dir (then it worked for one deployment)
  • I removed specific code in my deploy.rb
  • I completely removed the :linked_dirs
  • I tried several ways to configure :linked_dirs

I would be glad if someone has any idea what else i could try. :(

Bundler could not find compatible versions for gem "rails": In snapshot (Gemfile.lock): rails (= 4.2.7.1)

Posted: 08 Nov 2016 06:39 AM PST

I am upgrading to openproject lastest version 6, however while running bundle install, I am getting the following error:

Bundler could not find compatible versions for gem "rails": In snapshot (Gemfile.lock): rails (= 4.2.7.1)

In Gemfile: rails (>= 4.2.7.1, ~> 4.2.7)

health_check was resolved to 1.5.1, which depends on    rails (>= 2.3.0)    openproject-translations was resolved to 6.0.5, which depends on    rails (~> 4.2.3)    prototype-rails was resolved to 4.0.0, which depends on    rails (~> 4.0)    rails-angular-xss was resolved to 0.2.0.pre.pre, which depends on    rails (< 5.1, >= 5.0.0)    rails_autolink (~> 1.1.6) was resolved to 1.1.6, which depends on    rails (> 3.1)  

Any help would be appreciated.

Thanks, Rahul

some blog sharing pop up, show pinterest-502 error. while locally working fine everything

Posted: 08 Nov 2016 03:56 AM PST

a{:href => "javascript:postToPinit('#{b.blog_image.url}','#{strip_tags(b.description)}','#{redirect_url_pinterest}')"} Shre on Pinterest  

and my js

function postToPinit(image_url, description, url) {   window.open('http://pinterest.com/pin/create/button/?url=' + url + '&media=' + image_url + '&description=' + description + ' ' + url, 'sharer', 'toolbar=0,status=0,width=650,height=436');  }                                                

pop up shows 502 error, Our server is experiencing a mild case of the hiccups. We've reported it to the team.

"libgcc_s.so.1 must be installed for pthread_cancel to work" when starting thin on Debian

Posted: 08 Nov 2016 03:39 AM PST

I am using thin as development web server with Rails on Debian 7. Since I've updated Rails to 4.2.7.1 I cannot launch thin anymore and I'm getting this error message :

Using rack adapter  libgcc_s.so.1 must be installed for pthread_cancel to work  Aborted  

I have a libgcc_s.so.1 file in my /lib/i386-linux-gnu/ folder but somehow thin cannot seems to find it there.

I have tried every answer to this question but it didn't help.

Convert milliseconds to hours and mins in ruby

Posted: 08 Nov 2016 05:24 AM PST

I have the following Rails helper to convert milliseconds to hours and mins:

def get_duration_hrs_and_mins(duration)    hours = duration / (3600000 * 3600000)    minutes = (duration / 60000) % 60000    "#{hours}h #{minutes}m"   rescue    ""  end  

However it always just returns it in minutes (e.g. 364m) and doesn't show the hours... and keep the minutes under 60.

No comments:

Post a Comment