[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x

Ruby

Ruby is an open-source dynamic object-oriented interpreted language that supports multiple programming frameworks including functional, object oriented and imperative. It also has a dynamic type system and automatic memory management. Ruby focuses on simplicity and productivity. Ruby's market share spiked due to Ruby on Rails, a model-view-controller (MVC) framework for building web applications.

Share tech news, updates, or what's on your mind.

Sign up to Post

Hi. I have knocked out a Ruby On Rails website that lists HR documents; the plan being for a user to click on a button next to the document in the list and open the pdf with the HR policy.
Rails being Rails I have the list with 'Show' and 'Edit' buttons...but need a 'Display pdf' button, too. The pdfs are on the server, each named with the number of the primary key in the table (thus pdf /usr/var/www/html/docs/123456.pdf refers in the table to  id 123456). Does anybody know how to set up the code in the controller and view (index.html.erb) that can facilitate this, please?
0
Learn SQL Server Core 2016
LVL 12
Learn SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

i have a json file, which contains KV pairs like below.

{
"app1_ds1_ds_jndi": "value1",
"app1_ds1_ds_url": "value2",
"app1_ds1_ds_useri": "value3",
"app1_ds1_ds_pwd": "value4",


"app1_ds2_ds_jndi": "value5",
"app1_ds2_ds_url": "value6",
"app1_ds2_ds_user": "value7",
"app1_ds2_ds_pwd": "value8",


"app2_ds1_ds_jndi": "value9",
"app2_ds1_ds_url": "value10",
"app2_ds1_ds_user": "value11",
"app2_ds1_ds_pwd": "value12",

}


I want to parse the above file to grep for all app1 datasources, ignoring other apps like app2, app3 ..etc., and construct an array of hashes in ruby like below.




[{jndiname: "value1",  url_name:"value2" user_name: "value3", Password:"value4"},
{jndiname: "value5",  url_name:"value6" user_name: "value7", Password:"value8"}
]
0
How to connect on database phpmyadmin in ruby on rails? I already do rake db:migrate but it doesn't connect on my phpmyadmin. How do i do that?
0
Hello,
Im trying to translate this code from https://securionpay.com/docs/api#checkout-request-sign.
EXAMPLE SIGNING


export checkout_request='{"charge":{"amount":499,"currency":"EUR"}}'
export signature=`echo -n "$checkout_request" | openssl dgst -sha256 -hmac 'pr_test_tXHm9qV9qV9bjIRHcQr9PLPa' | sed 's/^.* //'`
echo -n "$signature|$checkout_request" | base64
        

EXAMPLE SIGNED CHECKOUT REQUEST


Y2Y5Y2UyZDgzMzFjNTMxZjgzODlhNjE2YTE4Zjk1NzhjMTM0Yjc4NGRhYjVjYjdlNGI1OTY0ZTc3OTBmMTczY3x7ImNoYXJnZSI6eyJhbW91bnQiOjQ5OSwiY3VycmVuY3kiOiJFVVIifX0=
				

Open in new window


to Ruby on Rails

I ended with

       
 checkout_request='{"charge":{"amount":5,"currency":"EUR","capture":true}}'
 secret_key = 'sk_test'
 @signature = Base64.urlsafe_encode64(OpenSSL::HMAC.hexdigest('sha256', checkout_request, secret_key) + "|" + checkout_request)

Open in new window


which isn't valid and its not exacly translation of the script.

When i test shell version with my secret key it works.
I tried Base64.urlsafe_encode64, encode64, strict_encode65, I tried digest instead of hexdigest. All kinds of way because I desperatly can't make it work. I think its about checkout_request data because it translates to this
 
2.5.0 :001 > '{"charge":{"amount":5,"currency":"EUR","capture":true}}'
 => "{\"charge\":{\"amount\":5,\"currency\":\"EUR\",\"capture\":true}}" 

Open in new window

and therefore signature is created with `\` before quote

question on stackoverflow: https://stackoverflow.com/questions/51506282/json-and-generating-signature
0
Hello,

Beautiful people of Experts-Exchange,

I have an app built on ruby on rails running on a Linode server. The app has iOS and android versions available as code in Bitbucket for source control.

The app uses cloud hosting on cloudspace.com and rackspace.com.

When I send text from one end to another for 2 registered users; it gets delivered. But when I send pictures; there is an image failure with only placeholder shown in receiver.

Log shows

OpenSSL::SSL::SSLError (SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed):
  app/controllers/api/v1/users_controller.rb:16:in `auth_cloud'

The bucket has a users_controller.rb which (on branch 'auth_cloud') in api_server/app/controllers/api/v1 that looks like -

def auth_cloud
    uri          =  URI 'https://identity.api.rackspacecloud.com/v2.0/tokens'
    data         = { 'auth' => { "RAX-KSKEY:apiKeyCredentials" => { 'username' => '***' , 'apiKey' => '***' }} }
    json_headers = {"Content-Type" => "application/json", "Accept" => "application/json"}
    http   = Net::HTTP.new uri.host, 443
    http.use_ssl = true
    res    = http.post uri.path, data.to_json, json_headers
    if res                                                                                               //This is line 16
      data = JSON.parse res.body
      render json: { response: data['access']['token']['id'] }
    else
      render json: { error: 'could not auth to rackspace'…
0
im getting this error message in my ruby on rails blog app and i have no idea why

this is my controller file:

class PostsController < ApplicationController
  def index
    @posts=Post.all.order("created_at DESC")
  end

  def new
    @post=Post.new
  end

  def show
    @post=Post.find(params[:id])
  end

  def create
    @post=Post.new(post_params)
    if @post.save
      redirect_to @post
    else
      render "new"
    end
  end

  def edit
    @post=Post.find(params[:id])
  end

  def update
    @post=Post.find(params[:id])
    if @post.update(params[:post].permit(:title, :body))
      redirect_to @post
    else
      render "edit"
    end
  end

  def destroy
    @post=Post.find(params[:id])
    @post.destroy
    redirect_to posts_path
  end

  private

  def post_params
    params.require(:post).permit(:title, :body)
  end

end

Open in new window


and this is my edit file: (i get the error when trying to delete a post and the link to the destroy path is on my edit page)

<font color="#BD004B">
    <h1 class="smallBorder">Edit Post</h1>
</font>
<br/>
<hr size="10" width="auto" color="#BD004B">

<%=render "form"%>

<ul>
  <li>
    <%=link_to "Delete", posts_path(@post), method: :destroy, data:{confirm:"Are you sure you want to delete this post?"}%>
  </li>
</ul>

Open in new window

0
0
Hello, I see below script starting like

require 'MonitoringScript'
class CheckSnmp < MonitoringScript

Open in new window


I am wondering what is MonitoringScript ? is it gem? and what below does?

class CheckSnmp < MonitoringScript

Open in new window


Really appreciate any help and guidance.
0
A traveller searches for trips from Bern to Berlin on Dec 25, 2013, from 8am (one-way).
A list of the 20 first results returned by a tool is given in the attached ex3-data.json file.

Tips: most fields are self-explanatory, while some may need explanation:
1. boo_return is true for a return trip, false otherwise
2. workTime_sec is the duration that the traveler can work during that part of the trip in seconds.
3. duration_out_sec is the duration of the corresponding outbound part of the trip, in seconds. For return trip, if applicable, there will be a similar field duration_in_sec for the duration of the inbound trip part.

Goals
1. Propose a solution to rank the list of results provided in the attached file.
2. Output the list of ranked results to a file named ex3-output.json.
   Each result must have two additional properties “rank” and “score”, respectively storing the final rank and the score of the trip (If applicable).

========================================
ex3-data.txt
0
How difficult is it for someone to make an AI interface that can be used on my computer, that can access anything from google maps when asking where something is located (like siri) all the way to being able to scan a hard drive for the contents held within it? I work for this small company and all we do is use google maps and take old hard drives and scan them for their contents, upon request by customer, and retrieve data deleted, lost, or just unreachable due to computer malfunction. I want to see if there is an easier way to do this, by using an AI to do all the hard work, and all we have to do is tell it to scan the drive and collect the lost data and store it into either a zip file or something as such. Please let me know thoughts. Am also flexible, doesn't have to be in ruby, but a lot of things we do, we use ruby based programs that's why I'm curious if its possible.
0
Amazon Web Services
LVL 12
Amazon Web Services

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

Thank you for watching.
I'm trying to create a custom filter on ActiveAdmin.
I tried to find a solution with referencing online articles.
But, I couldn't. Plese, help me.

There are two models called PointPayment and Contract.

PointPayment
# Table name: point_payments
#
#  id           :integer          not null, primary key
#  user_id      :integer
#  contract_id  :integer
#  amount       :float(24)
#  created_at   :datetime         not null
#  updated_at   :datetime         not null
#  state        :integer          default(0)
#  payment_type :integer          default(0)

class Contract < ActiveRecord::Base
  has_many :point_payments, dependent: :destroy
end

Contract
# Table name: contracts
#
#  id                         :integer          not null, primary key
#  client_id                  :integer
#  advisor_id                 :integer

class PointPayment < ActiveRecord::Base
  belongs_to :contract
end

Open in new window


I'd like to filter Contract with "payment_type."
But, Contract model hasn't payment_type.
So, I have to filter records of PointPayment model with payment_type at first and pick "contract_id" up from them.
And then, I filter Contract model records with the contract_ids.

The payment_type has four types 0 to 3.
But, I'll only use three types ( 1 to 3 ) for filtering.

Now, I wrote below codes. But, It doesn't work.
I'm stuck. I don't even know how I should search.

models/contract.rb
class Contract < ActiveRecord::Base
  scope :payment_type_one, -> { PointPayment.find_by(payment_type: 1) }
  scope :payment_type_two, -> { PointPayment.find_by(payment_type: 2) }
  scope :payment_type_three, -> { PointPayment.find_by(payment_type: 3) }

  scope :payment_types, lambda { |payment_types|
    case payment_types
    when 2
      pt = payment_type_one
      Contract.id(pt.contract_id)
    when 3
      pt = payment_type_two
      Contract.id(pt.contract_id)
    when 4
      pt = payment_type_three
      Contract.id(pt.contract_id)
    end
  }

  def self.ransackable_scopes(_auth_object = nil)
    %i(payment_types)
  end

end

Open in new window


adminn/contract.rb
ActiveAdmin.register Contract do
  filter :payment_types, as: :select, collection: proc { [%w(Type1 2), %w(Type2 3), %w(Type3 4)] }
end

Open in new window

0
I have inherited a cookbook from another developer and when I run "berks install" I get the following error output.

{dir removed}/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/solve-3.1.0/lib/solve/ruby_solver.rb:80:in `block in resolve': undefined method `name' for nil:NilClass (NoMethodError)
        from /{dir removed}/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/solve-3.1.0/lib/solve/ruby_solver.rb:79:in `each'
        from /{dir removed}/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/solve-3.1.0/lib/solve/ruby_solver.rb:79:in `inject'
        from /{dir removed}/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/solve-3.1.0/lib/solve/ruby_solver.rb:79:in `resolve'
        from /{dir removed}/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/solve-3.1.0/lib/solve.rb:64:in `it!'
        from /{dir removed}/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/berkshelf-5.6.4/lib/berkshelf/resolver.rb:78:in `resolve'
        from /{dir removed}/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/berkshelf-5.6.4/lib/berkshelf/installer.rb:176:in `install_from_universe'
        from /{dir removed}/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/berkshelf-5.6.4/lib/berkshelf/installer.rb:40:in `run'
        from /{dir removed}/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/berkshelf-5.6.4/lib/berkshelf/berksfile.rb:422:in `install'
        from /{dir removed}/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/berkshelf-5.6.4/lib/berkshelf/cli.rb:143:in `install'
        from /{dir …
0
I am working on a POC to read data from a DB using Logstash and create a JSON nested document and put it into elasticsearch. I am unable to create the JSON and was wondering using RUBY for the same however I am new to RUBY and need some help doing the same
The JSON I want created is
 { ParentId:1, ParentName:pName,
Child[
{
ChildId:1,
ChildName:cname1,
}

{
ChildId:2,
ChildName:cname2,
}


]
}


Any help in this regard will be appreciated. I need this urgently
0
I am trying to get a RoR application running on Ubuntu 15.10, the app runs on:
* Apache
* MySQL
* Ruby on Rails

Should I install Apache first, then CD to the Apache directory before installing rails? The reason I ask is there is one GEM that needs to be installed manually:
sudo gem install jquery-rails -v 3.1.4

Open in new window


I have just did a clean Ubuntu 15.10 and started installing Ruby, however I am thinking, should I have installed Apache first? Is there an order to installing RoR for Apache, where I need to be in the apache directories for GEM commands?

I am a Linux newbee, thanks in advance!
0
Hello,

I have two versions of SASS installed.

SASS (3.4.22, 3.4.21)

Should I uninstall one of them, or leave as is?

If i should uninstall, what command shall I issue at the command line? I am running windows10.

Thanks
0
I am migrating an existing Ruby on Rails application.   I have setup a development environment in Ubuntu with Ruby 1.8.7 and Rails 2.3.12 and SQLite 2.8.17.

I would like to download the production source and install on the development computer.   What do I need to download and move?
0
I’ve been trying to find alternatives to using sleep for some time and it seems that every single suggested method to avoid using sleep never works and I’m at the end of my rope.

      it 'finds the correct product when searching by job type', js: true do
        fill_in('filterrific_for_work_type', with: 'Central')
        # once again, sleep feels like the only thing that works
        #sleep 1 # TODO: find a better way..
        expect(find('#work_queue_items_filter_reset')).to have_content('Reset All Filters')
        expect(page).to have_link('IP Central Report',
                                  href: work_queue_item_path(@release.id))
      end

Open in new window


I also have this wait for ajax helper:

module CapybaraHelpers
  def wait_for_ajax
    Timeout.timeout(Capybara.default_max_wait_time) do
      loop until finished_all_ajax_requests?
    end
  end

  def finished_all_ajax_requests?
    page.evaluate_script('jQuery.active').zero?
  end
end

Open in new window


And in spec_helper.rb:

RSpec.configure do |config|
config.include CapybaraHelpers, type: :feature
End

Open in new window


This test breaks unless I add the sleep 1.  and I’ve tried so many iterations using things like ‘within’ ‘find’, ‘have_content’ ect.  This is really driving me crazy.
0
I’ve been trying to find alternatives to using sleep for some time and it seems that every single suggested method to avoid using sleep never works and I’m at the end of my rope.

     it 'finds the correct product when searching by job type', js: true do
        fill_in('filterrific_for_work_type', with: 'Central')
        # once again, sleep feels like the only thing that works
        #sleep 1 # TODO: find a better way..
        expect(find('#work_queue_items_filter_reset')).to have_content('Reset All Filters')
        expect(page).to have_link('IP Central Report',
                                  href: work_queue_item_path(@release.id))
      end

Open in new window


I also have this wait for ajax helper:

module CapybaraHelpers
  def wait_for_ajax
    Timeout.timeout(Capybara.default_max_wait_time) do
      loop until finished_all_ajax_requests?
    end
  end

  def finished_all_ajax_requests?
    page.evaluate_script('jQuery.active').zero?
  end
end

Open in new window


And in spec_helper.rb:

RSpec.configure do |config|
config.include CapybaraHelpers, type: :feature
End

Open in new window


This test breaks unless I add the sleep 1.  and I’ve tried so many iterations using things like ‘within’ ‘find’, ‘have_content’ ect.  This is really driving me crazy.
0
There are two models:

    # == Schema Information
    #
    # Table name: news
    #
    #  id         :integer          not null, primary key
    #  title      :string           not null
    #  content    :text             not null
    #  scope      :string           not null
    #  created_at :datetime         not null
    #  updated_at :datetime         not null
    #  person_id  :integer          not null
    
    # == Schema Information
    #
    # Table name: likes
    #
    #  id        :integer          not null, primary key
    #  like      :boolean
    #  person_id :integer          not null
    #  news_id   :integer          not null

Open in new window


Relation

    news has many likes
    like belongs to news

Open in new window

I want to get most liked news from query. Query should subtract count of likes equal true from likes equal false. The highest number is most liked news.
What I tried:
@most_liked_news = News.joins(:likes).where('likes.like = ?', true).group('news.id').order('COUNT(likes.like) DESC').first

Open in new window

Above returns news that has most positive likes. But it's not all good, because e.g. post with 10 positive and 1 negative will be better than post with 20 positivie and 15 negative(10 - 1 > 20 -15)
0
Microsoft Azure 2017
LVL 12
Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

There are three models:

    # Table name: activities_people
    #
    #  activity_id :integer          not null
    #  person_id   :integer          not null
    #  date        :date             not null
    #  id          :integer          not null, primary key
    #
    # Table name: activities
    #
    #  id          :integer          not null, primary key
    #  name        :string(20)       not null
    #  description :text
    #  active      :boolean          not null
    #  day_of_week :string(20)       not null
    #  start_on    :time             not null
    #  end_on      :time             not null

Open in new window


Third model is people.
Associations:

 
  class Activity < ActiveRecord::Base
      has_many :activities_people
      has_many :people, through: :activities_people
    end
    
    class ActivitiesPerson < ActiveRecord::Base
      belongs_to :person
      belongs_to :activity
    end
    
    class Person < ActiveRecord::Base
    has_many :activities, through: :activities_people
    end

Open in new window

Issue:
I don't know how to create validation method in ativities_person.rb to protect joining on activities, that my other training interests overlaps timely.

Example:

person_id:1 join to activity, that will 08.08.2016(date) and last 09:00(start_on) - 10:00(end_on).
 Same person want save to another activity, that will also be 08.08.2016 and last 09:30(start_on) - 10:30(end_on). Now
validation should throw error that he's save to other activity in same time(time ranges overlap). Validation first should check that dates match, next should check time overlaps of activities.

What I tried:

 

Open in new window

0
I have two models, `Genre` and `Book`. They both have a `has_and_belongs_to_many` association.
What i'm doing is scraping a site and collecting the information of each book. I'm running into an issue updating genres to an existing book and genre in my DB.

Below is an example of how my array of genres are going to come out.

    genres = ["Action", "Drama", "Romance"]

I was thinking of doing this to check if i already have the genre in the database and if it does exist it will update it.

    genre = Genre.where(title: genres).first_or_create
    anime.update(genres: genre)

I end up getting this error.

    `undefined method `each' for #<Genre:0x007f9059868bc0>

Is there a simple way for me to do this? This would really help me.
0
If I'm not mistaken we have a symbol and a hash but still I don't get why we have this syntax can you elaborate me or guide me what to read?
class Tweet < ActiveRecord::Base
  has_one :location, foreign_key: :tweeter_id, dependent: :destroy
end

Open in new window

Thanks
0
I get the following error below with the attached ruby script and text file. Please note you will need to include the text file in the command line after entering the ruby file name. I tried referring to the variable 'mystery_word' in the script as an array but get the same error. Please help. Thanks.

'hangman.rb:47:in `<main>': undefined method `each' for "<mystery word>":String (NoMethodError)'
ruby_hangman.txt
wordsHangman.txt
0
This is Chef cookbook question.

Question: I need to dynamically reference an index.html file located on github.com within the recipe.

Apache2:

template '/var/www/html/index.html' do
   source index.html.erb
end

In the above code, /var/www/html/index.html file is being replaced with index.html.erb located in <cookbook>/template/default/index.html.erb file. What I want is instead of index.html.erb, I need to use https://github.com/<repository>/myIndex.html

If there is any change in myIndex.html, it should reflect in /var/www/html/index.html realtime.

I appreciate your help.
0
I have a Ruby application that I have migrated to gtk3. Most things are working but changing the background color does not work for Entry's . I It works fine for buttons. The commands are of the form:

color = Gdk::RGBA.parse("lightblue1")
 widget.override_background_color(0, color)

gtk3 wants RGBA colors. Another report of this problem  said they only got it working using css . This requires using style & providers. Are there any examples of how to do this in Ruby.
0

Ruby

Ruby is an open-source dynamic object-oriented interpreted language that supports multiple programming frameworks including functional, object oriented and imperative. It also has a dynamic type system and automatic memory management. Ruby focuses on simplicity and productivity. Ruby's market share spiked due to Ruby on Rails, a model-view-controller (MVC) framework for building web applications.

Top Experts In
Ruby
<
Monthly
>