Monday, August 8, 2016

Apply a condition only on image which is nil Rails 4 | Fixed issues

Apply a condition only on image which is nil Rails 4 | Fixed issues


Apply a condition only on image which is nil Rails 4

Posted: 08 Aug 2016 08:00 AM PDT

I'm new to Rails so my code is probably ugly..

I have a loop which give me the 3 latest articles on my index page.

I added a condition to say "if there is no image in my article, give me a image from unsplash".

The issue is : that's apply the condition on the 3 images even if 2 of 3 images exists. I want that only the image which is nil get the unsplash image. How can I do that ?

<% @articles.last(3).in_groups_of(3, false).each do |group| %>      <div class="row">        <% group.each do |article| %>          <% if article.image.exists? %>            <div class="col-xs-12 col-sm-4">              <div class="card">                <style media>                  .card { background: linear-gradient(-225deg, rgba(30,30,30,0.6) 30%, rgba(46,46,46,0.5) 80%), url("<%= article.image.url(:medium) %>"); }                </style>                <img src="<%= article.user.image.url(:thumb) %>" alt="" class="avatar-small card-user">                <div class="card-description">                  <a href="<%= articles_path(article.slug) %>"><h3><%= article.title %></h3></a>                  <p><%= truncate(article.subtitle, length: 45, escape: false) %></p>                </div>              </div>            </div>       <% else %>            <div class="col-xs-12 col-sm-4">              <div class="card">                <style media>                  .card { background: linear-gradient(-225deg, rgba(30,30,30,0.6) 30%, rgba(46,46,46,0.5) 80%), url("http://unsplash.it/1280/500/?random"); }                </style>                <img src="<%= article.user.image.url(:thumb) %>" alt="" class="avatar-small card-user">                <div class="card-description">                  <a href="<%= articles_path(article.slug) %>"><h3><%= article.title %></h3></a>                  <p><%= truncate(article.subtitle, length: 45, escape: false) %></p>                </div>              </div>            </div>        <% end %>      <% end %>    </div>  <% end %>  

my controller :

class PagesController < ApplicationController    def index      @articles = Article.last(3)    end  end  

Thanks a lot for your help !

Facebook OAuth Callback redirected to API not supported

Posted: 08 Aug 2016 08:00 AM PDT

I'm trying to register Users through my API using Facebook OAuth.

The problem is I keep getting this error:

The redirect_uri URL is not supported  

the redirect_uri is:

redirect_uri=localhost%3A3000%2Fauth%2Ffacebook%2Fcallback  

or, simplified:

localhost:3000/auth/facebook/callback  

which is the URL where it's supposed to being redirected. (API is running on localhost:3000)

The client application is running on localhost:4000

These are my configurations in developers.facebook.com:

Settings > Basic

enter image description here

Products > Facebook Login Products > Facebook Login

rails Skip to a variable js

Posted: 08 Aug 2016 07:53 AM PDT

i have this function js

function load_custom_fields(id){     $('#custom_fields').html('<%= j render "custom_fields", f:f, id:'+ id +' %>');    }  

Skip to a variable , id returns a string , return = + id + how to pass id js to render

help me!

How to solve Mathematical Expressions in Rails 4 like 6000*70%?

Posted: 08 Aug 2016 07:54 AM PDT

I am using Dentaku gem to solve little complex expressions like basic salary is 70% of Gross salary. As the formulas are user editable so I worked on dentaku.

When I write calculator = Dentaku::Calculator.new to initialize and then enter the command calculator.evaluate("60000*70%") then error comes like below:

Dentaku::ParseError: Dentaku::AST::Modulo requires numeric operands from /Users/sulman/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/dentaku-2.0.8/lib/dentaku/ast/arithmetic.rb:11:in `initialize'

I have array is which formula is stored like: ["EarningItem-5","*","6","7","%"] where EarningItem-5 is an object and has value 60000

How can I resolve such expressions?

How to ignore pending migrations?

Posted: 08 Aug 2016 07:52 AM PDT

I have a Rails app that connects to another Rails app database. They have several common models. When using console, everything works fine (ActiveRecord queries tables properly), but when using a web server, Rails checks for pending migrations and raises error Migrations are pending. I want to pass this check as these 2 apps have different migrations. And just start the server. I tried:

config.active_record[:migration_error] = false  config.active_record.migration_error = false  

but no luck. How can I make Rails ignore those pending migrations? Skip this check? Or is there a way to name them somehow, or set appropriate mtime, to last migration file?

Ruby on Rails: Why doesn't my formatting work when downloading XLS?

Posted: 08 Aug 2016 07:35 AM PDT

Following RailsCast http://railscasts.com/episodes/362-exporting-csv-and-excel?autoplay=true I am trying to format the xls download, but with my below code it doesn't format the xls file but just opens up Excel (with no data and no file opened).

Mime_types.rb:

Mime::Type.register "application/xls", :xls  

Contacts_controller:

def index    @contacts = Contact.where(user_id: session[:user_id])    respond_to do |format|      format.html      format.csv { send_data @contacts.to_csv }      format.xls    end  end  

Contact model:

def self.to_csv(options = {})    CSV.generate(options) do |csv|      csv << column_names      all.each do |contact|          csv << contact.attributes.values_at(*column_names)      end    end  end  

Index.xls.erb:

<table border="1">    <tr>      <th>Firstname</th>      <th>Surname</th>      <th>Email</th>    </tr>    <% @contacts.each do |contact| %>    <tr>      <td><%= contact.firstname %></td>      <td><%= contact.surname %></td>      <td><%= contact.email %></td>    </tr>    <% end %>  </table>  

Can anyone tell me of the reason for this?

Can I note that when replacing the line format.xls in the controller format.xls { send_data @contacts.to_csv(col_sep: "\t") } it does download the XLS file but with no formatting, and also says that the file is corrupted.

Rails5 - Adding Foreign Keys to Existing Models in postgres

Posted: 08 Aug 2016 07:38 AM PDT

I have two models. An Events model and an EventOption. The Events will have_many :event_options.

My issue is that when I try to do a migration to add_foreign key :event_options, :events so that I can link them up, I get the following error:

ActiveRecord::StatementInvalid: PG::UndefinedColumn: ERROR:  column "event_id" referenced in foreign key constraint does not exist  : ALTER TABLE "event_options" ADD CONSTRAINT "fk_rails_3995702fad"  FOREIGN KEY ("event_id")    REFERENCES "events" ("id")  

Here's my schema.rb:

ActiveRecord::Schema.define(version: 20160806001743) do      # These are extensions that must be enabled in order to support this database    enable_extension "plpgsql"      create_table "event_options", force: :cascade do |t|      t.datetime "created_at",  null: false      t.datetime "updated_at",  null: false      t.float    "price"      t.text     "description"      t.string   "name"    end      create_table "events", force: :cascade do |t|      t.datetime "created_at",                null: false      t.datetime "updated_at",                null: false      t.string   "name"      t.boolean  "active",     default: true    end      create_table "users", force: :cascade do |t|      t.datetime "created_at",                     null: false      t.datetime "updated_at",                     null: false      t.string   "email",                          null: false      t.string   "encrypted_password", limit: 128, null: false      t.string   "confirmation_token", limit: 128      t.string   "remember_token",     limit: 128, null: false      t.index ["email"], name: "index_users_on_email", using: :btree      t.index ["remember_token"], name: "index_users_on_remember_token", using: :btree    end    end  

I know there are :id columns that work because I can play with them in the console. I know I'm missing something here to get the Foreign Keys working for the app, but for the life of me, I don't know what.

On publish getting multiple same requests pubnubv4 rails

Posted: 08 Aug 2016 07:59 AM PDT

I have a rails app that is API based using pub-nub v4. Same for client side(IOS/Android) using pub-nub.

Here are the steps we are doing:

1) On create any object we are subscribing two channel's and creating a listener.here.At same time on client end we are subscribing two channel's on basis of this object id.

2) So for any publish from IOS end for same channels creating multiple requests at web end.so multiple DB entries are going to create.

Here is the code sample of subscribing and unsubscribing.

$pubnub.add_listener("broadcast_#{broadcast.id.to_s}")    $pubnub.subscribe("broadcast_#{broadcast.id.to_s},broadcastLikes_#{broadcast.id.to_s}")       $pubnub.publish("broadcast_#{self.id.to_s}", { type: "StopBroadcast", text: text })  $pubnub.remove_listener("broadcast_#{self.id.to_s}")  $pubnub.unsubscribe("broadcast_#{self.id.to_s}, broadcastLikes_#{self.id.to_s}")  

Anyone can help me!

RHEL Upstart w/ Puma Jungle

Posted: 08 Aug 2016 06:57 AM PDT

I'm trying to create an upstart script for RHEL and puma jungle. The upstart scripts supplied by puma work for Ubuntu, but I don't think they're made for RHEL.

Is there a good resource where I can learn about RHEL scripts?

How can I get my puma rails app to start after server reboot/crash?

Application pushed to heroku but not working due to dotenv gem

Posted: 08 Aug 2016 07:07 AM PDT

I have pushed to heroku but the application will not run. I see that it is due to the dotenv gem. Is there a way around this? I need the dot-env gem in order to encrypt the basic auth user name and password. I'd prefer not to use devise or anything of that complexity as this is a simple application.

Below is my heroku terminal output, only issue is I dont really know how to spot errors/read the output.

  /app/config/application.rb:4:in `require': cannot load such file -- dotenv (LoadError)          from /app/config/application.rb:4:in `<top (required)>'          from /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:141:in `require'          from /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:141:in `require_application_and_environment!'          from /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:67:in `console'          from /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.5/lib/rails/commands/commands_tasks.rb:39:in `run_command!'          from /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.5/lib/rails/commands.rb:17:in `<top (required)>'          from /app/bin/rails:9:in `require'          from /app/bin/rails:9:in `<main>'            gem 'rails', '4.2.5'    gem 'pg'    gem 'sass-rails', '~> 5.0'    gem 'uglifier', '>= 1.3.0'    gem 'coffee-rails', '~> 4.1.0'    gem 'will_paginate', '~> 3.1.0'    gem 'jquery-rails'    gem 'turbolinks'    gem 'jbuilder', '~> 2.0'    gem 'sdoc', '~> 0.4.0', group: :doc    gem "font-awesome-rails"    gem 'dotenv-rails', :groups => [:development, :test]    gem 'will_paginate-bootstrap'    gem "paperclip", "~> 5.0.0"      group :development, :test do    # Call 'byebug' anywhere in the code to stop execution and get a debugger console    gem 'byebug'  end    group :development do    # Access an IRB console on exception pages or by using <%= console %> in views    gem 'web-console', '~> 2.0'    # gem 'dotenv-heroku'      # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring    gem 'spring'  end  

Structure Tags in rails

Posted: 08 Aug 2016 07:43 AM PDT

How build a Structure Tags in Rails like WordPress(permalink) ?

I have permalink column and I want to write user permalink options

for example :

%post_title% %year%  

export:

Post title 2016   

Can't disable popup blocking on chrome ruby + watir webdriver

Posted: 08 Aug 2016 07:24 AM PDT

I can't disable popup blocking on chrome, using ruby with watir webdriver.

I tried this:

profile['profile.default_content_settings.popups'] = 0  

but popup is still blocked. What's wrong?

Is Meteor mature enough to develop a CRM/ERP on top of it?

Posted: 08 Aug 2016 06:07 AM PDT

Is Meteor.js mature/stable enough and a good choice to build a small business CRM/ERP on top of it?

We are evaluating web development tool to build a web/mobile app for a facility management small company.

I accept all suggestion about where to start, I have experience in RubyOnRails development using MongoDB and some JS experience. I've found Meteor pretty interesting.

capybara and RSpec: ajax response not working

Posted: 08 Aug 2016 07:06 AM PDT

I'm working on writing Test cases using (RSpec and Capybara).

capybara (2.7.1) and   rspec (3.4.0)  rspec-core (3.4.4)  rspec-expectations (3.4.0)  rspec-mocks (3.4.1)  rspec-rails (3.4.2)  rspec-support (3.4.1)  

There are many answers are available but no luck!!!. These are the result which I found: 1, 2, and 3

capybara.rb

Capybara.asset_host = 'http://localhost:3000'  Capybara.default_max_wait_time = 5  

session_helpers.rb

module Features    module SessionHelpers      def sign_up_with(email, password, confirmation)        visit new_user_registration_path        fill_in 'Email', with: email        fill_in 'Password', with: password        fill_in 'Password confirmation', :with => confirmation        click_button 'Sign up'      end        def signin(email, password)        visit root_url        find(:xpath, "//a[@class='login_box_btn']").click        fill_in 'login_user_email',    with: email        fill_in 'login_user_password', with: password        click_button "LOGIN"      end    end  end  

features/users/sign_in_spec.rb

feature 'Sign-In and Sign-Out', :devise do  scenario 'user cannot sign in if not registered' do      signin('test@example.com', 'please123')      expect(page.find(:xpath, "//div[@id='login_message']")).to  have_content("Email not found. Please provide a valid email.")  end  

On expecting

find(:xpath, "//div[@id='login_message']") => ""  

But it should not be empty.

As I'm following RailsApps/rails-devise to get the things done all configuration are according to this repo.

Please do comment in case if someone need more info on this.

javascript ajax request in rails not able to pass values

Posted: 08 Aug 2016 06:13 AM PDT

I have a rails application in which I have following controller action.

def index     ....     ....        @currency = params["currency"].present? ? params["currency"] : "INR"        @check_in_date = params["arrival_date"].present? ? params["arrival_date"] : Date.today.to_s        @check_out_date = params["departure_date"].present? ? params["departure_date"] : (Date.today + 1).to_s     ....     ....  end  

I have javascript where I am trying to make an ajax request like this. filename.html.haml

  else{      hotel_id = id.slice(6)                  $.ajax({        url: "/single_hotel/"+hotel_id,        data: {check_in_date: #{@check_in_date}, check_out_date: #{@check_out_date}, longitude: #{@longitude}, latitude: #{@latitude}, rooms: #{@rooms}, adults: #{@adults}, children: #{@children}, currency: #{@currency} },        type: 'get'      });                }  

when I check the sources tab in chrome console I see this.

            $.ajax({                url: "/single_hotel/"+hotel_id,                data: {check_in_date: 2016-08-08, check_out_date: 2016-08-09, longitude: 34.854, latitude: 32.3213, rooms: 1, adults: 1, children: 0, currency: INR },                type: 'get'              });  

When I try to make the ajax request I get "VM18204:52 Uncaught ReferenceError: INR is not defined".

Also if I remove currency and make the request I get following values for check in & check out dates.

[1] pry(#<Bookings::HotelsController>)> params  => {"check_in_date"=>"2000",   "check_out_date"=>"1999",   "longitude"=>"34.854",   "latitude"=>"32.3213",  }  

Can someone please help me here.

No route matches {:action=>"show", :controller=>"scoo.....missing required keys: [:id]

Posted: 08 Aug 2016 07:57 AM PDT

I have a partial form for create and update...for the new it render the partial but when going for the edit one I keep getting this error

ActionController::UrlGenerationError in Scoopes#edit

no route matches {:action=>"show", :controller=>"scoopes", :id=>nil, :user_name=>#} missing required keys: [:id]

I search for an answer from old questions but no one solved my problem...the form is for creating scoopes....

the assosiaction between scoope and users is :

scoope belong_to user  and user has_many scoopes  

here is my scoope controller:

class ScoopesController < ApplicationController    before_action :authenticate_user!, except: [:show]    before_action :set_scoope, only: [:show, :edit, :update, :destroy, :index]    before_action :owned_scoope, only: [:edit, :update, :destroy]      def index      @scoopes = @user.scoopes.all    end      def show      @scoope = @user.scoopes.find(params[:id])    end      def new      @scoope = current_user.scoopes.build    end      def create      @scoope = current_user.scoopes.build(scoope_params)      if @scoope.save          redirect_to scoope_path(current_user.user_name, @scoope)      else          render 'new'      end    end      def edit      @scoope = @user.scoopes.find(params[:id])    end      def update      @scoope = @user.scoopes.find(params[:id])      if @scoope.update(scoope_params)          redirect_to scoope_path(@user, @scoope)      else          render 'edit'      end    end        def destroy      @scoope = @user.scoopes.find(params[:id])      @scoope.destroy      redirect_to scoopes_path    end      private      def scoope_params      params.require(:scoope).permit(:name)    end      def set_scoope      @user = User.find_by(user_name: params[:user_name])    end    def owned_scoope      unless @user == current_user          flash[:danger] = "this scope dont belong to you"          redirect_to root_path      end    end  end  

here is my partial form(I think maybe the problem somehow related to the edit path because when I try yo replace scoope with edit_scoope_path then it render the form under the edit page..but it will not solve my whale problem because it is a partial):

<div class="row">    <div class="col-md-5 formm">      <%= render 'shared/errors', obj: @scoope %>      <div class="well">        <%= form_for @scoope do |f| %>          <div class="form-group">            <%= f.label :name %><br/>            <%= f.text_area :name, rows: 6, class: 'form-control' %>          </div>          <div class="form-group">            <%= f.submit class: 'btn btn-primary'  %> <%= link_to "Back", :back, class: "btn btn-danger" unless current_page?(scoopes_path) %>          </div>        <% end %>      </div>    </div>  </div>  

here is my routes for scoopes:

               scoopes GET    /:user_name/scoopes(.:format)               scoopes#index                       POST   /:user_name/scoopes(.:format)               scoopes#create            new_scoope GET    /:user_name/scoopes/new(.:format)           scoopes#new           edit_scoope GET    /:user_name/scoopes/:id/edit(.:format)      scoopes#edit                scoope GET    /:user_name/scoopes/:id(.:format)           scoopes#show                       PATCH  /:user_name/scoopes/:id(.:format)           scoopes#update                       PUT    /:user_name/scoopes/:id(.:format)           scoopes#update                       DELETE /:user_name/scoopes/:id(.:format)           scoopes#destroy  

my scoope table:

create_table "scoopes", force: :cascade do |t|    t.string   "name"    t.integer  "user_id"    t.datetime "created_at", null: false    t.datetime "updated_at", null: false  end  

Routes:

devise_for :users, :controllers => { :registrations => "user/registrations" }  root "posts#index"   scope '/:user_name' do   resources :scoopes  end  get ':user_name', to: 'profiles#show', as: :profile    get ':user_name/edit', to: 'profiles#edit', as: :edit_profile    patch ':user_name/edit', to: 'profiles#update', as: :update_profile    ................  

Password contains special characters not saved correctly

Posted: 08 Aug 2016 07:21 AM PDT

Update: Fixed by setting config.pepper in devise.rb

I use Rails 4 and devise 3.4.1 . I built API to register and authenticate user. Clients that use my API are emberJS web app, IOS App and Android App, POST MAN Chrome app for development.

If i registered user with password contains special characters from POST MAN the user registered successfully and log in successfully. But when i register user from other clients the user registered successfully but can't log in again.

I checked the following points:

1- I checked request headers and same for all clients. (true)

2- I used rails debugger to ensure that server received password correctly.(true)

3- I have 3 environments development, staging, production. problem exist in staging and production but it works at development.

How to integrate google maps pin with form in AngularJS

Posted: 08 Aug 2016 05:46 AM PDT

I'm going to allow create pins to google map by users. Those pins will be visible for every logged users. How to do that using form and input with geocode? Maybe AngularJS? Any ideas?

disable sidekiq in staging

Posted: 08 Aug 2016 05:39 AM PDT

I've got sidekiq set up for in a rails app and everything is fine.

Now I want to disable it for stagin env only.

I can just change the redis password in YML file, but I am sure there must a better (more elegant way) to stop workers in only one env.

BTW, I kill the process in the box but every time I deploy to staging (capistrano-sidekiq), it creates a new process.

How to replace rails 3 Model.scoped by rails 4 Model.all

Posted: 08 Aug 2016 05:53 AM PDT

I am converting a project from rails 3 to 4.2. I found that scoped is deprecated. To me scoped is confusing. My current code in index controller is below

@customers = Customer.scoped  @customers = Customer.between(params['start'], params['end']) if (params['start'] && params['end'])  

So how can I remove Customer.scoped from above code but still keep the same functionality??

As some other articles suggested to use all instead of scoped. So I tried something like this

@customers = Customer.all  @customers = @customers.between(params['start'], params['end']) if (params['start'] && params['end'])  

I am not sure though if my converted code is okay or not.

Rails, move logic to out of the view

Posted: 08 Aug 2016 05:41 AM PDT

I am using 'globalize' gem to have my models translated into multiple languages.

I found the gem 'globalize-accessors' helpful when displaying inputs for several locales. The best method I found for listing all inputs is this one.

Is there a way to move all that code to helpers or sth. so that the views stay clean?

So, insted of

= simple_form_for @feature do |f|    - Feature.globalize_attribute_names.each do |lang|      = f.input lang    = f.submit  

I would only have to write

= simple_form_for @feature do |f|    = f.input :name    = f.submit  

Show current user as "Me" in select tag

Posted: 08 Aug 2016 05:49 AM PDT

I have used the below-written code to select the users

def user_for_select      User.pluck(:name, :id).unshift(['All', 'all'])  end  

But I want to display the current user's name as "Me" in the select tag.

Rails way to query on array inside JSON data type

Posted: 08 Aug 2016 05:16 AM PDT

I have a column in my table with JSON data type where I am storing an array.

Migration

class AddDataToStates < ActiveRecord::Migration    def change      add_column :posts, :edit_summary, :json    end  end  

Post

class Post < ActiveRecord::Base    serialize :edit_summary, JSON  end  

This is how the data is stored:

:id => 2,  :edit_summary => [    [0] {        "user_id" => 56,      "date" => "2016-08-09T07:46:04.555-04:00"    },    [1] {        "user_id" => 57,      "date" => "2016-08-08T06:35:44.345-04:00"    },  ]  

I referred this post and wrote a query which is working fine

SELECT *  FROM   posts, json_array_elements(edit_summary) as elem  WHERE  elem->>'date' BETWEEN '2016-08-07 00:00:00' AND '2016-08-10 23:59:59';  

Now my question is there any way to do same rails way?

Repopulate Multiple select Box - Ruby On Rails

Posted: 08 Aug 2016 04:52 AM PDT

I am using html.erb templates and bootstrap .when creating a post i choose multiple options from select box and save these values in database in the form of array because i'm using serialize :column_name option in my model . it works so far . but when i try to edit the post , select box values donot repopulate . I have tried the below options

My select box in _form.html.erb

<%= form_for(@post , url: { action: @definded_action }) do |f| %>  <%= f.select :skills, options_from_collection_for_select(@skills , :id,:title), {}, id: "sel1" ,class: "form-control selectpicker" , multiple: true%>  <% end %>  

when i debug in edit function where i am fetching skills , it shows me

@post.skills = ["1","2","3","4"]  

in edit function where i'm fetching it from database i have tried this

@post.skills = @post.skills.map(:&to_i)  

but no success. any help will be greatly appreciated :) -

Get all visible CKEditor instances

Posted: 08 Aug 2016 06:18 AM PDT

It is possible to loop through all the CKEditor instances like:

for(var instanceName in CKEDITOR.instances) {    ...  }  

Some of the CKEditors are hidden in my case. So, how is it possible to loop through the visible CKEditors?

ReferenceError: THREE is not defined in a Rails Project with the threejs-rails gem

Posted: 08 Aug 2016 04:40 AM PDT

I am working in a ruby on rails project with three.js. I installed the corresponding gem and in one of my java classes it worked just fine. Now this class uses a second class, the BVHLoader.js and suddenly both classes throw the same Error:

Uncaught ReferenceError: THREE is not defined

I dont know what I could have changed to suddenly call that Error.

in my own js class it is thrown in this line:

renderer = new THREE.WebGLRenderer();  

And the weird thing is that the Program still displays my Object.

Format response to friendly parsed json

Posted: 08 Aug 2016 05:06 AM PDT

So i have some web scraping coming back like this:

["SEvent({\"event_id\":\"ID\",\"date\":\"Sat  5 Nov 2016, 19:30\",\"suppress_b...  

Now what im wanting is to render this in a parsed json. This is how my render looks at the moment:

 respond_to do |format|         format.json  { render :json => {:testing => price1}}       end  

However this returns this:

{    "testing": [      "TMEvent({\"event_id\":\"ID\",\"date\":\"Sat  5 Nov 2016, 19:30\  

How do i make it so that it looks better, (more like this):

SEvent:{  event_id: ID,  date: Sat  5 Nov 2016, 19:30}  

(if i place this code into jsonformatter it works and looks exactly how i wanted it!)

Any help? Sam

Sass::SyntaxError: Undefined variable. But variable is defined

Posted: 08 Aug 2016 04:28 AM PDT

I'm crashing my head on the wall with a stupid scss error:

Sass::SyntaxError: Undefined variable: "$darker-grey"  app/assets/stylesheets/mobile/general.scss:36  app/assets/stylesheets/mobile/main.scss:6  

In my main scss file I have:

@import "compass";  @import "compass/reset";  @import "bourbon";  @import "mobile/variables.scss";  @import "mobile/mixins.scss";  @import "mobile/general.scss";  @import "mobile/general-profile.scss";  @import "mobile/buttons.scss";  @import "mobile/form.scss";  

Variables are imported before every other file that use them.

This is my variables file.

/****************************************************  *  * Varibles  *  ****************************************************/  $imgs: "mobile/";    /****************************************************  *  Colors  ****************************************************/    $background-color : #FFFFFF;  $foreground-color : #1F1F1F;    $light-gray  : #F7F7F7;  $medium-gray : #D6D6D6;  $gray        : #A3A3A3;  $gray-alt    : #3E3E3E;  $dark-gray   : #2B2B2B;  $darker-gray : #1F1F1F;  $sponsored-gray : #E7E7E7;  $green      : #82AA1E;  $dark-green : #0F6B18;  $orange     : #E25000;    /****************************************************  *  Fonts  ****************************************************/  $font-regular : "proxima-nova", arial, sans-serif;  $font-condensed : "proxima-nova-extra-condensed", arial, sans-serif;    /****************************************************  *  Fonts size  ****************************************************/  $font-smaller : 0.5em;  $font-small   : 0.75em;  $font-base    : 1em;  $font-big     : 1.8em;  $font-bigger  : 2.6em;    $font-footer-copy : 12px;  $font-title-page  : 32px;    /****************************************************  *  Z-index  ****************************************************/  $z-i-base           : 1;  $z-i-banner-comment : $z-i-base + 1;  $z-i-header-menu    : $z-i-banner-comment + 1;  $z-i-icon-hamburger : $z-i-header-menu + 1;    $z-i-modal : 100;  $z-i-btn-close : $z-i-modal + 1;  $z-i-modal-banner-comment : $z-i-btn-close + 1;  

The error is returned on this rule:

Extracted source (around line #36):      font-size   : $font-small;    font-weight : 300;    color       : $darker-grey;    @include display-flex();    @include flex-flow(column);  

Why $font-small, declared in the same file, is ok but $darker-grey no???

How can i resolve ActiveRecord::AssociationTypeMismatch error in rails?

Posted: 08 Aug 2016 07:28 AM PDT

I have LoadAcquisition Controller without a model,and used it based on the active type gem with nested attributes concepts in rails. But when i created the record the active type mimatch error will raise. I don't know how to resolve it,anyone please help me to resolve this error. My model

class LoadAcquisition < ActiveType::Object    attribute :email,:string    attribute :load_type_id,:integer    attribute :load_pick_from_date,:date    attribute :load_pick_to_date,:date    attribute :negotiated_price,:float    #attribute :source_id    #attribute :destination    attribute :notes,:text    attribute :truck_type_id,:integer    attribute :name,:string    attribute :landline_number,:integer    attribute :mobile_number,:integer    attribute :company_name,:string      validates :email, presence: true    validates :load_pick_from_date, presence: true    validates :load_pick_to_date, presence: true    #validates :source, presence: true    #validates :destination, presence: true    validates :notes, presence: true    validates :name, presence: true    validates :landline_number, presence: true    validates :mobile_number, presence: true    validates :name, presence: true      def load_acqu_generate        if User.find_by(:email=>self.email).nil?          Company.create(name: self.name, users:{name:self.name, email:self.email, landline_number:self.landline_number, mobile_number:self.mobile_number})        else          User.find_by(:email=>self.email).companies.create(name:self.company_name,loads:{price:self.negotiated_price,load_pick_from_date:self.load_pick_from_date,load_pick_to_date:self.load_pick_to_date})        end    end  end  

My Controller

def create    @load_acquisitions=LoadAcquisition.new(load_acquisition_params)    if @load_acquisitions.save      @load_acquisitions.load_acqu_generate     redirect_to root_url, notice: "Success!"    else     render "new"    end  end    private    def load_acquisition_params    params.require(:load_acquisitions).permit(:load_pick_from_date,:load_pick_to_date,:notes,:mobile_number,:landline_number,:email,:name,:load_type_id,:truck_type_id,:company_name)  end  

This is the screenshot of error I am getting

Why RVM requires YAML?

Posted: 08 Aug 2016 04:26 AM PDT

While installing RVM from, it is suggested to provide YAML source tar as well. Don't know why YAML is needed by RVM? ( link :-https://github.com/rvm/rvm-site/blob/master/content/rvm/offline.md) We can very well install it as a separate gem , right?

Please provide your insights.

No comments:

Post a Comment