Rails 5 Active Record Record Invalid Error

I have two Rails model namely Invoice and Invoice_details. An Invoice_details belongs to Invoice, and an Invoice has many Invoice_details. I'm not able to save Invoice_details via Invoice model using accepts_nested_attributes_for in Invoice. I get t...
more »

2017-06-17 15:06 (2) Answers

How to add conditions for json model association

Im trying to include an association but only ones based on its attribute's value Joo Model: def as_json(options = {}) super(include: [:foo, (:bar).where('bar.accepted = ?', true)]) end undefined method `where' for :bar:Symbol Doing super(i...
more »

2017-06-11 19:06 (1) Answers

Rails adding data to tables upon creation

I have two tables User (Devise) and Phones I would like for it when the user signs up threw registrations done with devise, the user_id and the type of phone is loaded into the Phones table But I am not sure how to do this. I have linked the User w...
more »

2017-06-01 09:06 (2) Answers

How to use MariaDB with Rails 5

I have read rails 5 supports MariaD but cant find any instruction on how to use it with rails 5. Do I still use the mysql2 gem? Do I need to use the libmariadbd-dev library. Are any other gems required? ...
more »

2017-06-01 03:06 (0) Answers

Rails engine extending views, not overriding

I am aware that I can override an applications view from within an engine by simply creating the same file within the engine and removing it from the application (eg: 'users/show.html.erb'). However, what I want is to be able to extend the applicat...
more »

2017-05-31 14:05 (1) Answers

Verify if user follow without a Exists SQL request

i'm trying to build a following action into my apps. To achieve that, I used the most common way, a join table (:followers) to link the users and the posts. But I'm encountering a little problem of efficience. Because for each of my posts, It's gen...
more »

2017-05-30 04:05 (1) Answers

How to use search on rails, use gem ransack?

I have a app about hotel, I have a model Room, RoomType: room.rb class Room < ApplicationRecord enum status: {freeing: true, using: false} belongs_to :room_type room_type.rb class Room < ApplicationRecord has_many :rooms I want to s...
more »

2017-05-07 22:05 (0) Answers

Rails Template Inline Code not running

I have a ruby on rails html.erb file with inline code in it like below. However, the code doesn't always run when somebody loads the page. It only prints to stdout the first time the page is loaded. <%puts "TESTING"%> Does rails cache my htm...
more »

2017-05-05 08:05 (2) Answers

Controller test for nested resources

can't go over the problem with CREATING INDEX ROUTE TEST for nested attribute. I've been trying all my ideas but nothing works I have Service model and ServiceRoute model. ServiceRoute belongs_to Service and Service has_many ServiceRoutes. H...
more »

2017-04-27 16:04 (1) Answers

How to differentiate Rails API calls in Newrelic?

I'm using Rails 5 to serve a website and a RESTful API, and I use Newrelic (newrelic_rpm gem) to monitor the application performance. At the moment, the gem monitor to all requests to one application name. let's say my routes looks something like...
more »

2017-04-27 06:04 (2) Answers

Ruby on Rails search function solutions

I'm new to Ruby on Rails, so I have serveral questions to my search function. Search View: <p> <%= form_tag students_path, :method => 'get' do %> <p> Advanced_search: <%= check_box_tag "advanced_search", value = "1" %> &l...
more »

2017-04-06 21:04 (1) Answers

activerecord model with 2 parent levels

A user can have many questions. Many users can participate on a question and provide multiple answers to the same question. Relation between users and questions seems to be working fine. Problem is with answers. model/user.rb has_and_belongs_to_m...
more »

2017-03-31 21:03 (1) Answers

rails dispatch event?

First off, I am totally new with gems and engines (eh. ruby); I am writing a handy engine which is going to filter requests based on the rules the user(developer) defines, currently my approach is the following: class ApplicationController < Acti...
more »

2017-03-29 19:03 (1) Answers

How to stub current_user in Rails 5?

How do I stub current_user in Rails 5? I expected this: @controller.stub :current_user, mock_user do end to work, but there is no @controller in ActionDispatch::IntegrationTest? I use sorcery gem for authentication. ...
more »

2017-03-25 23:03 (1) Answers