ruby-on-rails

  1. S

    Accessing a specific item in a JSON return in Rails

    I have this JSON from the NHL API, and I tried to access the value gamesPlayed: "teams"=>[ { "id"=>5, "name"=>"Pittsburgh Penguins", "link"=>"/api/v1/teams/5", "venue"=>{ "id"=>5034, "name"=>"PPG Paints Arena", "link"=>"/api/v1/venues/5034"...
  2. S

    Understanding routes with :path in Ruby on Rails

    I'm trying to understand routes in Ruby on Rails and it's very hard to find the right info just by googling. So this is my question: what routes does the following snippet define ? scope '/admin' do resource :photo, :only => [:edit], :path => '/d/:domain_name', :domain_name =>...
  3. S

    How to override a method of a ruby gem for certain conditions?

    I am trying to override one of the private methods of a gem only when certain conditions are met. I would like to use this method only if a certain condition is met else use the gem's method. module Net class FTP def makepasv if condition @sock.peeraddr[0] == 'AF_INET' ...
  4. R

    How many times does array appear in another array?

    I'm new to Ruby on Rails. This question seems to be answered in other programming languages but not RoR. I have an array with 3 items in it. array1 = [1, 2, 3] I then have items in another array which i want to check and see how many times array1 appear in array2: array2 = [1, 2, 3, 4, 5, 6...
  5. M

    RSpec/AnyInstance: Avoid stubbing using allow_any_instance_of problem

    Help me. I don't understand how to fix it. I tried to many variations... driver_iq_driver_spec.rb describe '.perform' do it 'correctly parse response' do driver = described_class.new(dot_application, background_check_type, provider_setting).perform expect(driver).to...
  6. S

    PG gem won't install in Rails app: Gem::Ext::BuildError: ERROR: Failed to build gem native extension

    I'm trying to deploy my Rails app to Heroku and when I add the pg gem to my gemfile and run bundle install I get an error: An error occurred while installing pg (1.1.3), and Bundler cannot continue. Make sure that `gem install pg -v '1.1.3'` succeeds before bundling. The bottom of my gemfile...
  7. T

    Rails wrap link_to on html code based on condition

    Is there a clean syntax to wrap link_to on html code based on condition? Because DRY, I don't want to repeat the same code. <% if condition? %> <%= link_to bla_bla_path do %> <p>Some html here</p> <% end %> <% else %> <p>Some html here</p> <% end %> I know there is link_to_if but it...
  8. F

    Simple Form behaving different than form_for

    Simple_form <%= simple_form_for(@book, wrapper: :horizontal_form, wrapper_mappings: { }, html: { class: 'form-horizontal' }) do |f| %> <%= f.error_notification %> <div class="image-upload"> <%= f.input :book_cover, as: :file , input_html: { class: 'fa fa-cloud-download'}%> </div>...
  9. S

    How can I show together in the views multiple attributes from different entries, that have the same name, like “nested” attributes?

    In a rental system, I have a model called Boardgame, with the attributes: name, copy and situation. Situation is another model, with belongs_to. So an example of my database: Catan, copy 1, available War, copy 1, rented War, copy 2, available War, copy 3, rented My code in the index view is...
  10. C

    Cannot Query Parent with Many to Many Association - Rails

    I have 3 models with the following structure: class Customer has_many :invoices has_and_belongs_to_many :locations end class Invoice belongs_to :customer end class Location has_and_belongs_to_many :customers end I'm trying to write a query that will grab invoices that have...
  11. C

    Is there a better way cancel the current request and redirect to an error page in Rails?

    Frequently when I'm dealing with controllers I have found the need to stop the current action and then show an error page. Currently I have a method to show my error page in application controller: class ApplicationController < ActionController::Base def show_error msg render file...
  12. C

    Undefined method exists? for Draper::CollectionDecorator

    I am trying to implement the Draper gem for my Rails project and having trouble getting it to work. I'm getting the error message: undefined method `exists?' for #Draper::CollectionDecorator:0x000055b625da7a10> The error seems to be coming up from a partial I'm rendering on my index view. The...
  13. O

    How to handle malformed json for a route with 'defaults: {format: :json}'?

    I have a url which is supposed to accept only json: put "/my_url" => "my_controller#my_actio", defaults: {format: :json} When I send malformed json to it, it doesn't make to an "action" at all and instead it throws an exception somewhere in Rails and thus my app ends up returning the error...
  14. P

    If statement inside an array creation ruby

    I am trying to do a if statement inside a array creation markers_index = Array.new @events.each_with_index do |event, index| ... markers_index << { type: 'Feature', geometry: { type: 'Point', coordinates: [event.longitude...
  15. X

    I am anticipating a patch request but am receiving a post instead

    I am submitting the form on my edit.html.erb and it is giving me an error for No route matches [POST] "/grouponepostings/17/edit". I am using simple forms in my document and am not sure how to specify that it is a patch request I seek. Here is routes.rb Rails.application.routes.draw do get...
  16. L

    Please review the problems below: Rails created post

    I dont't know why but when i'm trying to create post, i got this error. I created a scaffold "post" Then i wanted to get my posts in a different controller, in my Controller home. I put "belongs_to :home" in my Post.rb In this step, all is fine. But when i'm trying to create post, i got this...
  17. G

    Firefox is default but still get WebDriverError: unable to connect to chromedriver 127.0.0.1:9515

    I'm setting up Capybara for the first time and it seems to be calling Chrome instead of Firefox by default. At first I was getting the webdriver error: I was able to clear this by adding a gem 'chromedriver-helper' and the test now opens with chromium. I also tried adding this to both...
  18. A

    Issues in getting UI in proper format using ruby on rails

    I am working on a Ruby on rails project. I want to get the UI in the format as mentioned in the image below. I tried the below code, but not getting proper results. User can create controller dynamically from permission so the controller can be anything (User,Role,Permission etc) Kindly give...
  19. T

    Rails multiple join vào một phương thức

    Mình có một người dùng trong ứng dụng của mình có thể có nhiều đánh giá, kế hoạch và tài liệu. Đã có một mối quan hệ trong cơ sở dữ liệu của mình. Mình muốn hiển thị tất cả những điều này trong một tab duy nhất mà không cần truy vấn cơ sở dữ liệu quá nhiều lần. Mình đã cố gắng để làm một phương...
  20. K

    Theo dõi các class có cùng Namespace

    Mình đang tạo spy cho hai class thuộc cùng một Namespace với mục tiêu mong muốn mỗi class nhận các đối số cụ thể: allow(SibApiV3Sdk::SendSmtpEmail).to receive(:new).and_return(seb_send_email) allow(SibApiV3Sdk::SMTPApi).to receive(:new).and_return(seb_smtp_api) def seb_send_email...
Top