Friday, March 25, 2016

Reduce the execution time of jobs of sidekiq | Fixed issues

Reduce the execution time of jobs of sidekiq | Fixed issues


Reduce the execution time of jobs of sidekiq

Posted: 25 Mar 2016 06:59 AM PDT

I am currently working on an app which involves syncing of contacts on rails server. I am using redis server and sidekiq for performing contact syncing in the background. My database is mongodb and I am using mongoid gem as ORM. Workflow is a follows:

  1. Contacts on the phone are passed to the rails server through app and then on the rails server, it is queued in the redis server.
  2. Now cron job triggers sidekiq which connects to redis and completes the job.

One Job of sidekiq is as follows:

  1. it has array of contacts(size upto 3000).
  2. It has to process each of these contacts. By processing I mean make insert queries to DB.

Now the problem is that sidekiq takes insane amount of time to complete the job. On average it takes 50-70 sec to complete the job.

Following are the relevant files

sidekiq.yml

# Sample configuration file for Sidekiq.  # Options here can still be overridden by cmd line args.  #   sidekiq -C config.yml    :verbose: true  :concurrency:  5  :logfile: ./log/sidekiq.log  :pidfile: ./tmp/pids/sidekiq.pid  :queues:    - [new_wall, 1]#6    - [contact_wall, 1]#7    - [email, 1]#5    - [gcm_chat, 1]#5    - [contact_address, 1]#7    - [backlog_contact_address, 5]    - [comment, 7]    - [default, 5]  

mongoid.yml

development:    # Configure available database sessions. (required)    sessions:      # Defines the default session. (required)      default:            # Defines the name of the default database that Mongoid can connect to.            # (required).            database: "<%= ENV['DB_NAME']%>"            # Provides the hosts the default session can connect to. Must be an array            # of host:port pairs. (required)            hosts:              - "<%=ENV['MONGOD_URL']%>"            #username: "<%= ENV['DB_USERNAME']%>"            #password: "<%= ENV['DB_PASSWORD']%>"            options:                #pool: 12          # Change the default write concern. (default = { w: 1 })          # write:          # w: 1            # Change the default consistency model to primary, secondary.          # 'secondary' will send reads to secondaries, 'primary' sends everything          # to master. (default: primary)          # read: secondary_preferred            # How many times Moped should attempt to retry an operation after          # failure. (default: The number of nodes in the cluster)          # max_retries: 20            # The time in seconds that Moped should wait before retrying an          # operation on failure. (default: 0.25)          # retry_interval: 0.25    # Configure Mongoid specific options. (optional)    options:      # Includes the root model name in json serialization. (default: false)      # include_root_in_json: false        # Include the _type field in serializaion. (default: false)      # include_type_for_serialization: false        # Preload all models in development, needed when models use      # inheritance. (default: false)      # preload_models: false        # Protect id and type from mass assignment. (default: true)      # protect_sensitive_fields: true        # Raise an error when performing a #find and the document is not found.      # (default: true)      # raise_not_found_error: true        # Raise an error when defining a scope with the same name as an      # existing method. (default: false)      # scope_overwrite_exception: false        # Use Active Support's time zone in conversions. (default: true)      # use_activesupport_time_zone: true        # Ensure all times are UTC in the app side. (default: false)      # use_utc: false  test:    sessions:      default:        database: db_test        hosts:          - localhost:27017        options:          read: primary          # In the test environment we lower the retries and retry interval to          # low amounts for fast failures.          max_retries: 1          retry_interval: 0      production:    # Configure available database sessions. (required)    sessions:      # Defines the default session. (required)      default:        # Defines the name of the default database that Mongoid can connect to.        # (required).        database: "<%= ENV['DB_NAME']%>"        # Provides the hosts the default session can connect to. Must be an array        # of host:port pairs. (required)        hosts:          - "<%=ENV['MONGOD_URL']%>"        username: "<%= ENV['DB_USERNAME']%>"        password: "<%= ENV['DB_PASSWORD']%>"        pool: 10        options:      # Configure Mongoid specific options. (optional)    options:  

Model.rb

def retry_save_contact_dump(c_dump_id)        c_dump = ContactDump.where(_id: c_dump_id, status: ContactDump::CONTACT_DUMP_CONS[:ERROR]).first        return false if c_dump.blank?        user = User.where(_id: c_dump.user_id).first        puts "retry_save_contact_dump"        user.save_contacts_with_name(c_dump.contacts)        c_dump.status = ContactDump::CONTACT_DUMP_CONS[:PROCESSED]        c_dump.error_msg = ""        c_dump.save      rescue => e        c_dump.status = ContactDump::CONTACT_DUMP_CONS[:CANTSYNC]        c_dump.error_msg = e.message        c_dump.save     end      def save_contacts_with_name(c_array)      m_num = Person.get_number_digest(self.mobile_number.to_s)      c_array.each do |n|        next if m_num == n["hash_mobile_number"]        p = Person.where(h_m_num: n["hash_mobile_number"]).first_or_create        save_friend(p) #if p.persisted?        p.c_names.create(name: n["name"], user_id: self.id)      end    end  

ContactDump.rb

class ContactDump    include Mongoid::Document    include Mongoid::Timestamps::Created    include Mongoid::Timestamps::Updated      field :contacts,   type: Array    field :status,     type: Integer, default: 0    field :user_id,    type: BSON::ObjectId    field :error_msg,  type: String      CONTACT_DUMP_CONS = {FRESH: 0,  PROCESSED: 1, ERROR: 2, CANTSYNC: 3}  end  

How can I speed up the processing of jobs? I tried with permutation of increasing concurrency of sidekiq in sidekiq.yml and pool of mongoid.yml, but no help.

How do whatsApp and other messaging apps deal with contact syncing?

If some other info is required, please ask. Thanks.

Ruby in Cloud9, root route won't change

Posted: 25 Mar 2016 06:50 AM PDT

I am just getting started in ruby on rails, but I can't seem to get the root route to successfully change. Instead of showing "hello, world!" Like I would expect it to, I just keep getting the default rails welcome page. Not sure if this is a syntax error or some nuance of cloud 9 I am not aware of.

routes.rb file

Rails.application.routes.draw do      root 'application#hello'    end  

application_controller.rb

class ApplicationController < ActionController::Base    # Prevent CSRF attacks by raising an exception.    # For APIs, you may want to use :null_session instead.    protect_from_forgery with: :exception      def hello      render text: "hello, world!"    end  end  

redirect_to an instance variable does not work in Rails 4

Posted: 25 Mar 2016 07:00 AM PDT

I'm completely new to Rails. Just started from *http://guides.rubyonrails.org/getting_started.html While trying I'm stuck with redirect_to problem like below error -

NoMethodError in SwversionsController#create  undefined method `sw_versions_url' for #<SwversionsController:0xa38d158>  Rails.root: C:/Sites/edisonprojectmanagement  Application Trace | Framework Trace | Full Trace  app/controllers/swversions_controller.rb:19:in `create'*  

This error occurs after clicking submit button. I found the model is working fine and data is saved in my postgresql database. I think problem is with my redirect_to method.

My SwVersionsController code looks like -

class SwversionsController < ApplicationController  def index    end  def show      @swversion = SwVersion.find(params[:id])    end  def new    end    def create      @swversion = SwVersion.new(swversion_params)      @swversion.save      redirect_to @swversion  end    private  def swversion_params      params.require(:swversion).permit(:sw_version, :description)  end  end  

And the new.html.erb code is -

<h1> New SW versions </h1>  <%= form_for :swversion, url: swversions_path do |f| %>  <p>   <%= f.label :sw_version, "SW Version" %> <br>   <%= f.text_field :sw_version %>  </p>  <p>      <%= f.label :description, "Description" %> <br>      <%= f.text_area :description %>  </p>  <p>      <%= f.submit "Submit" %>  </p>  <% end  %>  

My routes.rb is pretty simple

Rails.application.routes.draw do resources :swversions get 'welcome/index

Someone please help me to banish this problem

Creating a tram timetable with ruby on rails

Posted: 25 Mar 2016 06:35 AM PDT

I am trying to create an application which lists tram times for a station to the next. I have been given large amounts of data in an excel spreadsheet. The data consists of Lines (EAST, WEST, NORTH, SOUTH). Each of these lines include a list of stops(stations). Each of the stations consist of a massive list of times from day to night. The system should take a look at current time and render out all lines, stations and times based on many different queries (mainly searching start to end stations).

The excel table is laid out for only ONE line like:

Station 1  07:00 07:30 08:50 ...  Station 2  07:15 07:45 08:55 ...  Station 3  07:18 08:00 09:05 ...  

think of the stations as stops. The distance between the first journey from Station 1 to Station 2 is 15 minutes. Then the next tram from station1 starts at 7:30. There are many of these excel documents represented as lines.

I am using mongoid in rails so my models are like:

class Line    include Mongoid::Document    include Mongoid::Timestamps    embeds_many :stations      field :line, type: String  end    class Route    include Mongoid::Document    include Mongoid::Timestamps    embedded_in :station      field :time, type: Time  end    class Station    include Mongoid::Document    include Mongoid::Timestamps    embeds_many :routes    embedded_in :line, inverse_of: :stations       field :name, type: String  end  

A line has many stations, a station belongs to line.

A Station has many routes,a route belongs to station.

I know I can import the excel data as it is large but i am having a little difficulty trying to work with these models. How would I be able to store this data is this way and later query based on my requirement or would I have to create my model like line1, line 2, line 3. or am I right?

ruby on rails regexp or ends_with

Posted: 25 Mar 2016 06:58 AM PDT

I'm trying to prevent users from overdoing certain actions.

My problem is that I don't know what the best way is to check if the path of the action matches with what I define in the YAML file. As I see it could be either regex or something like ends_with method.

At the moment I have the following half ready code. I'm not sure if I should define the paths in the YAML the way I currently do and also not sure if I call a proper comparison in rack_attack.rb.

Could somebody help me out and explaining me why his/her recommended solution is the best here?

YAML:

logins_ip:      limit: 5      period: 30      path: /users/sign_in    post_comment_creation:       limit: 5      period: 45      # Full route is /posts/:post_id/post_comments but post_id not required      # since I wanna prevent users from commenting more than 5/45sec to all the      # posts. Yet I may could use some regex that matches any number.      path: /post_comments    messages_creation:      limit: 10      period: 10      # Here I need this exact route since I wanna prevent users from      # messaging more than 10/10sec in a given conversation      path: conversations/:conversation_id/messages    default:      period: 60      limit: 10      method: POST  

rack_attack.rb

@config = YAML.load_file('config/rack_attack.yml').with_indifferent_access        def from_config(key, field)          @config[key][field] || @config[:default][field]      end        @config.keys.each do |key|          Rack::Attack.throttle(key, limit: from_config(key, :limit), period: from_config(key, :period)) do |req|          req.ip if /#{from_config(key, :path)}/.match(req.path.to_s) && from_config(key, :method) == req.env['REQUEST_METHOD']      end  end  

How to pass data-attribute from a button to it's corresponding modal

Posted: 25 Mar 2016 06:37 AM PDT

In my rails app, I have a view with some images.

<div class="item-images">    <div class="row">        <% @user_item.user_item_images.each_with_index do |image, index| %>        <% if (index + 1) % 5 == 0 %>          </div><div class="row">        <% end %>        <div class="image-container">          <a class="fancybox" rel="group" href="<%= image.picture.large.url %>"><img class="img-thumbnail img-circle" src="<%= image.picture.thumb.url %>" alt="" /></a>            <% if @user.eql?(current_user) && @user_item.primary_image_id != image.id %>            <button class="btn btn-xs btn-danger delete-image" data-id="<%= image.id %>" data-toggle="modal" data-target="#delete-image-modal">              <i class="fa fa-trash-o fa-lg"></i>            </button>            <% if @user_item.primary_image_id != image.id %>              <button class="btn btn-xs btn-info make-primary" data-id="<%= image.id %>" data-toggle="modal" data-target="#make-primary-modal">                <i class="fa fa-thumb-tack fa-lg"></i>              </button>            <% end %>          <% end %>            </div>      <% end %>  

As you can see I have two buttons associated with each image. The corresponding modals:

<!-- Delete Image Modal -->  <div id="delete-image-modal" class="modal" tabindex="-1" role="dialog" aria-labelledby="delete-image" aria-hidden="true">    <div class="modal-dialog">      <div class="modal-content">        <div class="modal-header">          <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>          <h4 id="delete-image">Are you sure you want to delete this image?</h4>        </div>        <div class="modal-footer">          <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">Cancel</button>          <%= link_to 'Delete', '', method: :delete, :class => 'btn btn-danger' %>        </div>      </div>    </div>  </div>    <!-- Make Primary Modal -->  <div id="make-primary-modal" class="modal" tabindex="-1" role="dialog" aria-labelledby="make-primary" aria-hidden="true">    <div class="modal-dialog">      <div class="modal-content">        <div class="modal-header">          <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>          <h4 id="make-primary">Are you sure you want to make this the primary image for your item?</h4>        </div>        <div class="modal-footer">          <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">Cancel</button>          <%= link_to 'Make Primary', make_primary_path(????), :class => 'btn btn-info' %>        </div>      </div>    </div>  </div>  

The make_primary_path brings us to a controller action which changes an attribute of the modal's associated image:

  def make_primary      @user_item = UserItemImage.find(params[:user_item_image_id]).user_item      @user_item.update_attributes(primary_image_id: params[:id])      flash[:notice] = "primary image set"      redirect_to :back    end  

The route for this action:

get 'user_item_images/:user_item_image_id/make_primary', to: 'user_item_images#make_primary', as: :make_primary  

My problem is generating the link in the "Make Primary Modal". How do I get the data-id from the button and use that in the link_to helper?

Need a third party text chat api to integrated into angularjs-rails app [on hold]

Posted: 25 Mar 2016 05:29 AM PDT

I require a third party text chat application to be integrated into my angular + rails web application and ionic framework mobile application.The primary feature this app should provide is for users to communicate in real time with each other, almost on the similar lines of gmail text chat. I am basically looking for an open source api, however any good paid version api if available are also welcome.Can someone suggest me such existing applications.

Use RSpec let(:foo) across examples

Posted: 25 Mar 2016 04:56 AM PDT

I'm using let(:foo) { create_foo() } inside my tests. create_foo is a test helper that does some fairly time expensive setup.

So everytime a test is run, foo is created, and that takes some time. However, the foo object itself does not change, I just want to unit test methods on that object, one by one, seperated into single tests.

So, is there a RSpec equivalent of let to share the variable across multiple examples, but keep the nice things like lazy loading (if foo isn't needed) and also the automatic method definition of foo so that it can be used in shared examples, without referencing it with a @foo?

Or do I have to simply define a

def foo    create_foo()  end  

Undefined method `toggle!' for #:ActiveRecord_AssociationRelation:

Posted: 25 Mar 2016 05:50 AM PDT

I've just got this problem in my controller, and I don't understand what's going on. It returns an undefined method toggle! for Like::ActiveRecord_AssociationRelation: Or for my create action every thing works but not with the update action. This is a basic like controller to like and unlike an event, someone and so on.

class LikesController < ApplicationController      before_action :authenticate_user!      def create      @project=Project.find(params[:project_id])      @like= @project.likes.where(user:current_user).first_or_initialize( name:current_user.first_name)      @like.toggle(:heart)      @like.save       Notification.create(user:current_user, user_name: current_user.first_name, action:'like', recipient:@project.subject)      redirect_to project_path(@project)    end          def update      @project=Project.find(params[:project_id])      @like= @project.likes.where(user:current_user)      @like.toggle(:heart)      @like.save      Notification.create(user:current_user, user_name: current_user.first_name, action:'Unlike', recipient:@project.subject)       redirect_to project_path(@project)      end   end  

How can I show comment username in Ruby on Rails?

Posted: 25 Mar 2016 05:11 AM PDT

I'm writing a simple blog with authentication, and I'm stuck with a little problem - I need the comment belong to current user and display his name. so:

  1. I created a User model with username:string
  2. Post.rb has_many :comments, dependent: :destroy
  3. User.rb has_many :comments
  4. Comment.rb belongs_to :post belongs_to :user
  5. I mage a migration addUserIdToComments user_id:integer
  6. In comments_controller.rb I wrote @comment.user = current_user
  7. In my view I have <%= comment.user.username %>

In result I have a NameError undefined local variable or method comment for #<#<Class:0xb93859dc>:0xb4b2a2b4> I've already looked over here, but it didn't help :(

comments_controller.rb

def create      @post = Post.find(params[:post_id])      @comment = @post.comments.create(comment_params)      @comment.user = current_user      if @comment.save          redirect_to post_path(@post)      else          render 'comments/form'      end  end    private    def comment_params      params.require(:comment).permit(:username, :body)  end   

show.html.erb

<div id="post_content">      <h2><%= @post.title %></h2>      <p><%= @post.body %></p>  </div>  <div id="comments">      <h2 class="comments">Комментариев: <%= @post.comments.count %></h2>      <%= render @post.comments %>      <%= render "comments/form" %>  </div>  

_comment.html.erb

<div class="comment_content">      <p><%= comment.user.username %></p>      <p><%= comment.body %></p>      <p><%= time_ago_in_words(comment.created_at) %></p>  </div>  

_form.html.erb

<div id="comment_form">      <h3 class="form_title">Оставить комментарий</h3>      <p><%= comment.user.username %></p>      <%= form_for ([@post, @post.comments.build]) do |f| %>          <p>              <%= f.label :Комментарий %>              <%= f.text_area :body %>          </p>          <p>              <%= f.submit %>          </p>      <% end %>  </div>  

rspec and apartment gem - switching subdomain host in feature spec

Posted: 25 Mar 2016 04:11 AM PDT

For the last several hours i have been fighting with rspec feature test. I am using apartment gem for subdomains . User can create account with subdomain field. Then he is redirected to http://user_subdomain.lvh.me/admin. This work very well in my development database. Problem comes from my feature rspec test. Below is my code

  scenario 'User can sign up' do      visit root_path      click_link 'Create account'      fill_in 'Email', with: 'test@test.com'      fill_in 'Subdomain', with: 'test'      fill_in 'Password', with: 'test1234'      fill_in 'Confirm Password', with: 'test1234'      click_button 'Create'      Capybara.app_host = "http://test.lvh.me"      Capybara.always_include_port = true        expect(page).to have_content('Hello from the dashboard.', wait: 5)        Apartment::Tenant.drop('gabinettttt')    end  

This gave me this error:

 ActionController::RoutingError:     No route matches [GET] "/admin"  

I know that this problem comes from Capybara switching host and only happen inside my test database. What is the proper way to test sign up user with subdomain?

Rails device and redirect

Posted: 25 Mar 2016 04:25 AM PDT

Im use device for sign_in\up

and have before_action :authenticate_user!

My problem is when user not logged in and i click to sign in it calls form for sign_in and after fill it redirect me on the same page

For example- i'm not logged in and i'm on root page and want to see products/1 i clicking to show modal pops up i enter my credentials and it redirects me to the same page

But after sign in i want to be at products/1

session controller

class SessionsController < Devise::SessionsController    respond_to :js    layout false    def create      self.resource = warden.authenticate(auth_options)        if resource && resource.active_for_authentication?        sign_in(resource_name, resource)      end    end    end  

template create.js.erb

<% if user_signed_in?%>  <%= request.referrer%>    window.location.href='<%= request.referrer %>'  <% else %>    $('#login_popup input').parent().addClass('inputbox_error');    $('#log_error_messages').show();    $('input').keydown(function(){      $(this).parent().removeClass('inputbox_error')      $('#log_error_messages').hide();    })  <% end %>  

what should i change after <% if user_signed_in?%>?

Rails: How to Unit test for validations of nested attributes?

Posted: 25 Mar 2016 04:09 AM PDT

I have a the following has_many model associations in my app:

User < Company < Deed < Subtransaction,

where Deed accepts_nested_attributes_for :subtransactions. I wish to test my Model validations using Minitest and fixtures.

I have trouble, however, testing the nested attributes for validity. For example , If I clear all nested attributes using

@deed.subtransactions.clear I correctly get a test response that the model is not valid.

However

@deed.subtransactions.first.num_shares = " " does not seem to work.

How do I properly test these nested attributes for validity?

My test:

  class DeedTest < ActiveSupport::TestCase            def setup              @user = users(:dagobert)              @newco = companies(:newco)              params = { :deed =>                     {                     :date => deeds(:inc_new).date,                     :subtransactions_attributes =>                          { '1' =>                                {                                :shareholder_name => "Shareholder 1",                                :num_shares => subtransactions(:new_subt1).num_shares                                },                            '2' =>                                 {                                :shareholder_name => "Shareholder 2",                                :num_shares => subtransactions(:new_subt2).num_shares                                }                           }                    }                }             @deed = @newco.deeds.new(params[:deed])             end            # test: does not raise any error messages             test "num_shares should be present for a subtransaction" do                @deed.subtransactions.first.num_shares = nil                assert_not @deed.valid?             end                        # test passing: The params are submitted correctly and pass validation           test "fixture values should be valid" do              assert @deed.valid?          end            # test passing: I can test the validity of deed attributes          test "date should be present" do              @deed.date = " "              assert_not @deed.valid?          end                # test passing: when I clear @deed.subtransactions the object is no longer valid           test "a subtransaction should be present" do               @deed.subtransactions.clear              assert_not @deed.valid?          end    end  

Include module or extend module in a ruby Class

Posted: 25 Mar 2016 04:23 AM PDT

Just getting my head around Ruby

I have a question related to inheritance is the include or extend is a way of inheritance in Ruby ?

What is deference between inheritance & includeing a module in ruby ?

Rails search method

Posted: 25 Mar 2016 05:45 AM PDT

I have tried using sql to write a simple search method, I have so far written this;

User.where("username LIKE '#{input}'")  

the input variable is 'adam', however I don't want to find the username's that are equal to 'adam' I want to find usernames that include 'adam' or include the letter 'a' etc.... I was wondering how I would go about doing that? I am not very familiar with sql queries.

Thanks

How to use increment method for strong parameter

Posted: 25 Mar 2016 04:04 AM PDT

What I'd like to do is to increment the value in the association model when I update.

schedule has_many rooms and rooms belongs_to schedule. I'd like to increment day in the room model.

accepts_nested_attributes_for :rooms, allow_destroy: true is also defined in the schedule.rb

Although fields except day will be inputted via view, I'd like to update only day automatically.

I tried to use increment method and so on, but I haven't figured out how to apply.

The view image as I expect is as followings;

Day1  schedule_title1 (Mar 25, 2016)      room_name1  

After update;

Day1  schedule_title1 (Mar 25, 2016)      room_name1  Day2  schedule_title2 (Mar 26, 2016)      room_name2  

schema.rb

  create_table "rooms", force: :cascade do |t|      t.string   "name"      t.integer  "schedule_id"      t.integer  "day",   default: 1   #I'd like to increment when I update      ...    end  

schedlues_controller.rb

class SchedulesController < ApplicationController  ...    def update        #I tried some code here before update        if @schedule.update(schedule_params)        flash[:success] = "schedule updated!"        redirect_to root_url      else        render 'edit'      end    end   ...    private        def schedule_params        params.require(:schedule).permit(:title, :departure_date,  rooms_attributes: [:id, :_destroy, :room, :day])      end  

When I press "Add room" button and update after entering some, I'd like to increment day.

_schedule_form.html.erb

<%= simple_nested_form_for(@schedule) do |f| %>      <%= f.label :title %>    <%= f.text_field :title, class: 'form-control' %>    <%= f.label :departure_date %>    <%= f.text_field :departure_date, class: 'form-control' %>      <div id="room">      <%= f.simple_fields_for :rooms do |r| %>        <%= r.input :room %>      <% end %>      <%= f.link_to_add "Add room", :rooms, data: {target: '#room'}, class: "btn btn-primary" %>    </div>    <% end %>  

It would be appreciated if you could give me any suggestion.

Rails: How to setup a Unit test for my model with nested attributes?

Posted: 25 Mar 2016 04:18 AM PDT

I have a the following has_many / belongs_to model associations in my app:

User < Company < Deed < Subtransaction,

where Deed accepts_nested_attributes_for (and validates_associated) :subtransactions. I wish to test my Model validations using Minitest and fixtures.

I've set up my test by explicity defining the hash of the params submitted to my model.

My Model test:

   class DeedTest < ActiveSupport::TestCase            def setup              @user = users(:dagobert)              @newco = companies(:newco)              params = { :deed =>                     {                     :date => deeds(:inc_new).date,                     :subtransactions_attributes =>                          { '1' =>                                {                                :shareholder_name => "Shareholder 1",                                :num_shares => subtransactions(:new_subt1).num_shares                                },                            '2' =>                                 {                                :shareholder_name => "Shareholder 2",                                :num_shares => subtransactions(:new_subt2).num_shares                                }                           }                    }                }             @deed = @newco.deeds.new(params[:deed])             end      <my tests here>    end  

Is this the proper way to setup my test? Or are there more elegant or Rails-like methods?

Rails 5 set Authorization header

Posted: 25 Mar 2016 04:23 AM PDT

I got JSON Web Token login going but am in the process of fixing my Rails 5 Controller tests.

I am trying to pass my JWT auth token to my GET request header.

So far, in my User Controller test, I have this test:

test "users should return list of users" do      User.create(@bob)      auth_token = log_in_as(@bob)        request.headers['Authorization'] = "JWT #{auth_token}"          get users_path          assert_response :success        assert_not response.body.empty?    end  

So far that doesn't work, I get response not authenticated.

If I change it to like so:

 test "users should return list of users" do      User.create(@bob)      auth_token = log_in_as(@bob)        get users_path, nil, { HTTP_AUTHORIZATION: "JWT #{auth_token}" }        puts "response = #{response.body}"        assert_response :success        assert_not response.body.empty?    end  

I get this expected response:

response = {"users":[{"id":298486374,"name":"MyString","email":"MyString","cats":[]},{"id":980190962,"name":"MyString","email":"MyString","cats":[]},{"id":980190963,"name":"Bob","email":"bob@gmail.com","cats":[]}]}  

but I also get a DEPRECATED WARNING:

DEPRECATION WARNING: ActionDispatch::IntegrationTest HTTP request methods will accept only the following keyword arguments in future Rails versions: params, headers, env, xhr

Examples:

get '/profile', params: { id: 1 }, headers: { 'X-Extra-Header' => '123' }, env: { 'action_dispatch.custom' => 'custom' }, xhr: true

So what is the recommended way to set HTTP Authorization header in Rails 5 ?

ActionController::UnknownFormat in Devise::RegistrationsController#new. ".user" appended in URL

Posted: 25 Mar 2016 03:40 AM PDT

I have worked with devise before but i can't understand what i did wrong this time.All the related questions doesn't explain it as well. As soon as i click the SignUp link, i get the error as follows

ActionController::UnknownFormat in Devise::RegistrationsController#new  

in line number 207

(options.delete(:responder) || self.class.responder).call(self, resources, options)    else  207: raise ActionController::UnknownFormat    end  end  

However, if i change my link from

  <%= link_to "Sign up", new_user_registration_path(resource_name) %>  

to

  <%= link_to "Sign up", new_user_registration_path %>  

the signup page loads just fine. Another thing to note is that when i click the signup link, my url looks like http://localhost:3000/users/sign_up.user and not like http://localhost:3000/users/sign_up which should be the case.

I referred Rails 4 Devise 3.1.1 ActionController::UnknownFormat in Devise::RegistrationsController#new and found the idea to remove the resource_name and it seems to work. However, i cant understand why. Thanx in Advance

file upload error in boxr gem

Posted: 25 Mar 2016 03:00 AM PDT

I am using boxr gem to upload the file in BOX cloud.I am uploading a file from my local then it through an error.At the same time when i copying the file in server and then going to upload,it successfully upload in BOX cloud.

Below is my code:-

@box_client = Boxr::Client.new(access_token)    #Get root Folder    #@root_folders = @box_client.root_folder_items.folders    #Select file upload folder    folder = @box_client.folder_from_path('/DRIVE/')    #Upload a file    file = @box_client.upload_file("C:\\#{params[:file]}", folder, content_created_at: Time.now,    content_modified_at: Time.now,preflight_check: true, send_content_md5: true)  

In params[:file], getting correct file path.

error:-   Errno::ENOENT in BoxApiController#upload   No such file or directory @ rb_file_s_size - C:\<my_file_name>  

error line :- file = @box_client.upload_file("C:\\#{params[:file]}", folder, content_created_at: Time.now, ...

What is the wrong in above code?

Request by jsonb field in Rails to Postgresql

Posted: 25 Mar 2016 02:50 AM PDT

I am a newbie with jsonb. I have next data in that field:

[{"language": "en:ru", "specializations": [10]}]  

How can I select all records when language include, for example "en" (only part of key "language"? Is it possible?

How to make css available for gmail using sendgrid

Posted: 25 Mar 2016 02:28 AM PDT

I am using Sendgrid api for my rails application to send email but in gmail is not supporting the css written within head tag what should I do to make css working.

Checkboxes only work on first page - Datatables, rails

Posted: 25 Mar 2016 04:37 AM PDT

Senario: So basically I'm using DataTables and have checkboxes on its first column. My DataTables have multiple pages (pagination).

The Problem: When I check a few boxes on a page (could be any page), AND also check a few on OTHER pages.

The results only gets saved if I am on the current page

I'm quite new to datatables/javascript and can't really figure out how to solve this issue.

$('#formDataTable').DataTable({           responsive: true,           autoWidth: true,           "bFilter": true,           "bRetrieve": true,           "bInfo": true,           "sPageFirst": false,           "sPageLast": false,  });  

I have read these SO pages. Checkboxes will only work on current pagination page in jQuery datatables Link is currently dead to this question -> Pagination with selected check boxes. Checkboxes will only work on current pagination page. jQuery datatables

Rails, Installed Gem version and Gemfile.lock version

Posted: 25 Mar 2016 05:07 AM PDT

I have a problem.

Gemfile.lock is always committed if bundle is updated.

And today, when I deploy web application, I see this error message,

Could not find jwt-1.5.3 in any of the sources  

jwt-1.5.2 is installed in deployed server at shared gem path.

I think bundle install new jwt-1.5.3 gem because the specified version (1.5.3) in Gemfile.lock and installed version (1.5.2) is not equal.

Why cannot bundle install jwt gem?

Should bundle install that gem if Could not find jwt-1.5.3?

ngFileUpload with rails

Posted: 25 Mar 2016 04:38 AM PDT

I wanted to upload file when i submit the form. I am using ngFileUpload at the front end and server is on rails. Following is the code the i have written :

<form name="form" ng-submit="submit()">    <input type="text" ng-model="data.username"/>    <input type="text" ng-model="data.address">     <input type="file" id="map" ngf-select ng-model="data.map" name="file"                 accept="image/*" ngf-max-size="2MB"                 ngf-model-invalid="errorFile">  </form>  

On form submit, i could see the data(on browser console) object containing all the values(including the object of map/image). But when i check on server side, map is showed as {} i.e empty object.

Could someone help me resolve the same.

Print \n as actual newline in terminal

Posted: 25 Mar 2016 02:44 AM PDT

In my RSpec email tests I render some text views with newlines:

class MyMailer < ActionMailer::Base    def email1      @foo = "Hello"      @bar = "World"      mail(to: "test@example.com", subject: "Foobar")    end  end  

This is the view email1.text.erb

<%= @foo %>    <%= @bar %>  

And this is my test:

it 'renders output' do    body = MyMailer.email1.body    puts body  end  

When I print the email body in terminal, ruby returns \n instead of an actual newline:

Hello\n\nWorld  

For debugging purpose it would be nice to have the actual newlines instead of \n printed in my terminal. Is there a way to do this?

Rails 4 - Heroku - production errors

Posted: 25 Mar 2016 02:14 AM PDT

I'm new to coding and learning on the go. I find it difficult to decipher what the heroku logs are telling me. I just tried to push the master branch to heroku and got an error directing me to the logs. The logs say the following. I can barely understand the english let alone make out what it might mean.

Can anyone see the problem I need to focus on to fix this?

heroku logs  2016-03-25T08:20:21.086021+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.4/lib/active_record/relation.rb:515:in `load'  2016-03-25T08:20:21.086023+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.4/lib/active_record/relation/delegation.rb:46:in `each'  2016-03-25T08:20:21.086025+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/rolify-5.0.0/lib/rolify/dynamic.rb:13:in `load_dynamic_methods'  2016-03-25T08:20:21.086022+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/activerecord-4.2.4/lib/active_record/relation.rb:243:in `to_a'  2016-03-25T08:20:21.086028+00:00 app[web.1]:    from /app/app/models/user.rb:2:in `<class:User>'  2016-03-25T08:20:21.086026+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/rolify-5.0.0/lib/rolify.rb:33:in `rolify'  2016-03-25T08:20:21.086030+00:00 app[web.1]:    from /app/app/models/user.rb:1:in `<top (required)>'  2016-03-25T08:20:21.086042+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:274:in `require'  2016-03-25T08:20:21.086043+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:274:in `block in require'  2016-03-25T08:20:21.086044+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:240:in `load_dependency'  2016-03-25T08:20:21.086046+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:274:in `require'  2016-03-25T08:20:21.086048+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:360:in `require_or_load'  2016-03-25T08:20:21.086061+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:184:in `const_missing'  2016-03-25T08:20:21.086049+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:494:in `load_missing_constant'  2016-03-25T08:20:21.086062+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.4/lib/active_support/inflector/methods.rb:261:in `const_get'  2016-03-25T08:20:21.086063+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.4/lib/active_support/inflector/methods.rb:261:in `block in constantize'  2016-03-25T08:20:21.086065+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.4/lib/active_support/inflector/methods.rb:259:in `each'  2016-03-25T08:20:21.086067+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.4/lib/active_support/inflector/methods.rb:259:in `inject'  2016-03-25T08:20:21.086069+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.4/lib/active_support/inflector/methods.rb:259:in `constantize'  2016-03-25T08:20:21.086080+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:566:in `get'  2016-03-25T08:20:21.086081+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:597:in `constantize'  2016-03-25T08:20:21.086082+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/devise-3.4.1/lib/devise.rb:302:in `get'  2016-03-25T08:20:21.086084+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/devise-3.4.1/lib/devise/mapping.rb:80:in `to'  2016-03-25T08:20:21.086085+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/devise-3.4.1/lib/devise/mapping.rb:75:in `modules'  2016-03-25T08:20:21.086087+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/devise-3.4.1/lib/devise/mapping.rb:92:in `routes'  2016-03-25T08:20:21.086089+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/devise-3.4.1/lib/devise/mapping.rb:159:in `default_used_route'  2016-03-25T08:20:21.086101+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/devise-3.4.1/lib/devise/mapping.rb:69:in `initialize'  2016-03-25T08:20:21.086102+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/devise-3.4.1/lib/devise.rb:336:in `new'  2016-03-25T08:20:21.086103+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/devise-3.4.1/lib/devise.rb:336:in `add_mapping'  2016-03-25T08:20:21.086104+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/devise-3.4.1/lib/devise/rails/routes.rb:224:in `block in devise_for'  2016-03-25T08:20:21.086105+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/devise-3.4.1/lib/devise/rails/routes.rb:223:in `each'  2016-03-25T08:20:21.086107+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/devise-3.4.1/lib/devise/rails/routes.rb:223:in `devise_for'  2016-03-25T08:20:21.086109+00:00 app[web.1]:    from /app/config/routes.rb:17:in `block in <top (required)>'  2016-03-25T08:20:21.086126+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:268:in `load'  2016-03-25T08:20:21.086127+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:268:in `block in load'  2016-03-25T08:20:21.086111+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.4/lib/action_dispatch/routing/route_set.rb:434:in `instance_exec'  2016-03-25T08:20:21.086123+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.4/lib/action_dispatch/routing/route_set.rb:434:in `eval_block'  2016-03-25T08:20:21.086124+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/actionpack-4.2.4/lib/action_dispatch/routing/route_set.rb:412:in `draw'  2016-03-25T08:20:21.086125+00:00 app[web.1]:    from /app/config/routes.rb:1:in `<top (required)>'  2016-03-25T08:20:21.086132+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:268:in `load'  2016-03-25T08:20:21.086130+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:240:in `load_dependency'  2016-03-25T08:20:21.086143+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.4/lib/rails/application/routes_reloader.rb:40:in `block in load_paths'  2016-03-25T08:20:21.086144+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.4/lib/rails/application/routes_reloader.rb:40:in `each'  2016-03-25T08:20:21.086145+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.4/lib/rails/application/routes_reloader.rb:40:in `load_paths'  2016-03-25T08:20:21.086148+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.4/lib/rails/application.rb:170:in `reload_routes!'  2016-03-25T08:20:21.086152+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.4/lib/active_support/lazy_load_hooks.rb:36:in `call'  2016-03-25T08:20:21.086167+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.4/lib/active_support/lazy_load_hooks.rb:45:in `block in run_load_hooks'  2016-03-25T08:20:21.086147+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.4/lib/rails/application/routes_reloader.rb:16:in `reload!'  2016-03-25T08:20:21.086168+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.4/lib/active_support/lazy_load_hooks.rb:44:in `each'  2016-03-25T08:20:21.086150+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/devise-3.4.1/lib/devise/rails.rb:14:in `block in <class:Engine>'  2016-03-25T08:20:21.086169+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.4/lib/active_support/lazy_load_hooks.rb:44:in `run_load_hooks'  2016-03-25T08:20:21.086154+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.4/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook'  2016-03-25T08:20:21.086173+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.4/lib/rails/initializable.rb:30:in `instance_exec'  2016-03-25T08:20:21.086175+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.4/lib/rails/initializable.rb:30:in `run'  2016-03-25T08:20:21.086177+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.4/lib/rails/initializable.rb:55:in `block in run_initializers'  2016-03-25T08:20:21.086172+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.4/lib/rails/application/finisher.rb:55:in `block in <module:Finisher>'  2016-03-25T08:20:21.086194+00:00 app[web.1]:    from /app/vendor/ruby-2.2.2/lib/ruby/2.2.0/tsort.rb:429:in `each_strongly_connected_component_from'  2016-03-25T08:20:21.086205+00:00 app[web.1]:    from /app/vendor/ruby-2.2.2/lib/ruby/2.2.0/tsort.rb:347:in `block in each_strongly_connected_component'  2016-03-25T08:20:21.086210+00:00 app[web.1]:    from /app/vendor/ruby-2.2.2/lib/ruby/2.2.0/tsort.rb:345:in `each'  2016-03-25T08:20:21.086179+00:00 app[web.1]:    from /app/vendor/ruby-2.2.2/lib/ruby/2.2.0/tsort.rb:226:in `block in tsort_each'  2016-03-25T08:20:21.086181+00:00 app[web.1]:    from /app/vendor/ruby-2.2.2/lib/ruby/2.2.0/tsort.rb:348:in `block (2 levels) in each_strongly_connected_component'  2016-03-25T08:20:21.086213+00:00 app[web.1]:    from /app/vendor/ruby-2.2.2/lib/ruby/2.2.0/tsort.rb:345:in `call'  2016-03-25T08:20:21.086213+00:00 app[web.1]:    from /app/vendor/ruby-2.2.2/lib/ruby/2.2.0/tsort.rb:345:in `each_strongly_connected_component'  2016-03-25T08:20:21.086216+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.4/lib/rails/application.rb:352:in `initialize!'  2016-03-25T08:20:21.086215+00:00 app[web.1]:    from /app/vendor/ruby-2.2.2/lib/ruby/2.2.0/tsort.rb:203:in `tsort_each'  2016-03-25T08:20:21.086215+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.4/lib/rails/initializable.rb:54:in `run_initializers'  2016-03-25T08:20:21.086214+00:00 app[web.1]:    from /app/vendor/ruby-2.2.2/lib/ruby/2.2.0/tsort.rb:224:in `tsort_each'  2016-03-25T08:20:21.086217+00:00 app[web.1]:    from /app/config/environment.rb:5:in `<top (required)>'  2016-03-25T08:20:21.086217+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:274:in `require'  2016-03-25T08:20:21.086219+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:274:in `block in require'  2016-03-25T08:20:21.086220+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:240:in `load_dependency'  2016-03-25T08:20:21.086222+00:00 app[web.1]:    from /app/config.ru:3:in `block in <main>'  2016-03-25T08:20:21.086221+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.4/lib/active_support/dependencies.rb:274:in `require'  2016-03-25T08:20:21.086240+00:00 app[web.1]:    from /app/config.ru:in `new'  2016-03-25T08:20:21.086224+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/rack-1.6.4/lib/rack/builder.rb:55:in `instance_eval'  2016-03-25T08:20:21.086227+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/rack-1.6.4/lib/rack/builder.rb:55:in `initialize'  2016-03-25T08:20:21.086241+00:00 app[web.1]:    from /app/config.ru:in `<main>'  2016-03-25T08:20:21.086245+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/rack-1.6.4/lib/rack/server.rb:299:in `build_app_and_options_from_config'  2016-03-25T08:20:21.086242+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/rack-1.6.4/lib/rack/builder.rb:49:in `new_from_string'  2016-03-25T08:20:21.086241+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/rack-1.6.4/lib/rack/builder.rb:49:in `eval'  2016-03-25T08:20:21.086244+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/rack-1.6.4/lib/rack/builder.rb:40:in `parse_file'  2016-03-25T08:20:21.086248+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.4/lib/rails/commands/server.rb:61:in `app'  2016-03-25T08:20:21.086251+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/rack-1.6.4/lib/rack/server.rb:336:in `wrapped_app'  2016-03-25T08:20:21.086247+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/rack-1.6.4/lib/rack/server.rb:208:in `app'  2016-03-25T08:20:21.086270+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:39:in `run_command!'  2016-03-25T08:20:21.086263+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/rack-1.6.4/lib/rack/server.rb:272:in `start'  2016-03-25T08:20:21.086266+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:75:in `tap'  2016-03-25T08:20:21.086264+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.4/lib/rails/commands/server.rb:80:in `start'  2016-03-25T08:20:21.086264+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:80:in `block in server'  2016-03-25T08:20:21.086267+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:75:in `server'  2016-03-25T08:20:21.086270+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.4/lib/rails/commands.rb:17:in `<top (required)>'  2016-03-25T08:20:21.086284+00:00 app[web.1]:    from bin/rails:8:in `<main>'  2016-03-25T08:20:21.086272+00:00 app[web.1]:    from bin/rails:8:in `require'  2016-03-25T08:20:22.133222+00:00 heroku[web.1]: State changed from starting to crashed  2016-03-25T08:20:22.119281+00:00 heroku[web.1]: Process exited with status 1  2016-03-25T08:22:00.423386+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=www.cttr.com request_id=3311cef7-19ae-4309-8020-53f88bcb630f fwd="49.191.132.150" dyno= connect= service= status=503 bytes=  2016-03-25T08:22:01.417500+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=www.cttr.com request_id=cd78c604-f5e3-48d5-9bd7-f974b7f61da4 fwd="49.191.132.150" dyno= connect= service= status=503 bytes=  2016-03-25T08:25:54.618347+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=www.cttr.com request_id=4fb1a6ed-3ef6-48f7-b1a5-fde8200b2529 fwd="49.191.132.150" dyno= connect= service= status=503 bytes=  2016-03-25T08:25:55.206739+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=www.cttr.com request_id=dc0d2a42-9937-4a4a-9815-d3c520951ef8 fwd="49.191.132.150" dyno= connect= service= status=503 bytes=  2016-03-25T08:31:51.288633+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=www.cttr.com request_id=b3b64814-3915-47f3-9032-30d8cdf4c0ec fwd="49.191.132.150" dyno= connect= service= status=503 bytes=  2016-03-25T08:31:51.957639+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=www.cttr.com request_id=c85281e9-1c34-474f-a153-ebe5085c11f6 fwd="49.191.132.150" dyno= connect= service= status=503 bytes=  

How to make has_two relationship in ruby on rails?

Posted: 25 Mar 2016 12:58 AM PDT

I have an employee model and address model. Now employee can have two addresses one is permanent and other is temporary.

I want the relationship that employee has two addresses one is permanent and other is temporary.

Also how can I save address for the employee in employee's controller while creating employee?

How can I dynamically determine which column is passed to friendly_id in order to watch it for changes?

Posted: 25 Mar 2016 12:42 AM PDT

I'm using the very useful option:

# config/initializers/friendly_id.rb    # ...  config.use Module.new {    def should_generate_new_friendly_id?      slug.blank?    end  }  

The issue is that I use friendly_id on 3 or 4 different models for which the attribute to watch for a change is differrent. For some it's name, others title. Is there a way to dynamically retrieve the attribute symbol that was passed to friendly_id :title, use: :slugged to prevent this being necessary in models?

# app/models/foo.rb  class Foo < ActiveRecord::Base    # ...      friendly_id :title, use: :slugged      def should_generate_new_friendly_id?      super || title_changed?    end  end  

```

Ideally I'm looking for something like:

# config/initializers/friendly_id.rb    # ...  config.use Module.new {    def should_generate_new_friendly_id?      slug.blank? || friendly_id_attribute_changed?    end  }  

Can this be achieved?

apache or nginx - which server to use for rails app deployment?

Posted: 24 Mar 2016 11:58 PM PDT

I am using paperclip in my rails application and want to deploy it on server. Which is good to use apache or nginx? Why?

1 comment:

  1. Thanks for sharing such a Excellent Blog! We are linking too this particularly great post on our site. Keep up the great writing.
    ruby assignment help

    ReplyDelete