answerstu

Trying to figure out why my rails app crashes in heroku?

I am brand new to heroku, trying to deploy a Rails app for the first time. When I open it, it crashes. Here is the logs, just wondering if anybody can make sense of it? 018-02-28T03:49:38.908155+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.3.0/gems/railties-5.1.4/lib/rails/command.rb:44:in `invoke'2018-02-28T03:49:38.908156+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.3.0/gems/railties-5.1.4/lib/rails/commands.rb:16:in `<top (required)>'2018-02-28T03:49:38.908160+00:00 app[web.1]: from bin/rails:9:in `require'2018-02-28T...Read more

ruby on rails - Blank Heroku app throwing H14 error

I just created a blank Heroku app using command 'heroku create' and navigated to the address designated to the app. The page read as follows: Application Error An error occurred in the application and your page could not be served. Please try again in a few moments. If you are the application owner, check your logs for details.I checked the logs in the command line, and it said: 2014-07-03T17:02:42.854237+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/" host=aqueous-beach-3520.herokuapp.co...Read more

ruby on rails - Using `joins()` for first an INNER JOIN then a LEFT JOIN of the next table

I am trying to avoid string interpolating my joins in Rails because I've noticed a decrease in flexibility when chaining queriers together. That is, I feel that joins(:table1) is much more flexible than joins('inner join table1 on table1.id = this_table.table1_id').What I would like to accomplish is:FROM table1INNER JOIN table2 on table2.id = table1.table2_idLEFT JOIN table3 on table3.id = table2.table3_idinner join allHowever, I can't figure out how to do it using Rails parlance:Table1.joins(table2: :table3)Results in an INNER join on the fin...Read more

rails - wrap HTML element around text of link_to() in ruby code without disabling all escaping

This is pretty basic but I'm not having any luck finding anything in the Rails documentation. There is a view helper method (Ruby code, not HAML) that returns link_to(user_controlled_text, destination, options)and I need to wrap an HTML element (namely <bdi>) around the user_controlled_text. If I dolink_to("<bdi>#{user_controlled_text}</bdi>", ...)then my element is treated as part of the user-controlled text to be escaped. Fair enough. How do I tell Rails not to escape the <bdi> and </bdi> but still escape the...Read more

ruby on rails - undefined method in users login test

I've just finished the chapter 8 of https://www.railstutorial.org/book/basic_login and the site is online (check here: https://peaceful-river-79951.herokuapp.com/). The only problem is in the final test:test "login with valid information followed by logout" do get login_path post login_path, params: { session: { email: @user.email, password: 'password' } } assert is_logged_in? assert_redirected_to @user follow_redirect! assert_template 'users/show' assert_select "a[href=?]", login_path, count: 0 ...Read more

rails: nested form with 2 foreign keys in table

I have a model "Post" which belongs_to "Group." The url is like this .../groups/26/posts/1 everything was working fine until I needed to add a user name to each post so I added a new foreign key to the Posts table for "User" and made the Post model belongs_to :user, and in the User model added has_many :posts. My issue is that I don't know how to create a new post so that I can get both the group_id and user_id added to the posts table.This works to populate the user_id foreign key of the Posts table. I need to call group in here somehow b...Read more

ruby on rails - Iterate through parameters array and ActiveRecord:Relation

I have a controller which needs to implement bulk update. (However, it needs to set specific values to each object vs the same value for all objects).Here is the array which the controller will get[ { "task_id": 1, "some_property": "value1" }, { "task_id": 2, "some_property": "value2" },]I need to find all tasks and for each task update the property to a provided value.The obvious solution istask_ids = params[::_json].map { |task| task[:task_id] }tasks = Task.where(id: task_ids)tasks.each do |task| params[::_json].each do |tas...Read more

Creating collections of posts with Rails 5 (as in Pinterest Boards)

I have over 500 posts and growing rapidly. I want to give a feature for users to create collections [title, description, posts] and assign posts to them. 1 post can belong to many collections from different users. Example: User A creates a collection named "DARK DESIGNS"User A clicks "add to collection" button in post/show page and selects her own "Dark Design" collectionUser A goes into another post and assigns more posts into "Dark Design"User A sees list of her collections at her profileQuestion:How should I structure this collections featur...Read more

ruby on rails - Configure screenshots file names for Rails5/RSpec

It looks like for Rails5/RSpec systems tests, the default is to use selenium-webdriver gem to take screenshots when a spec fails. Is there a way to configure the format of the filename for the screen shot that gets taken? I've seen this is possible with capybara-screenshot gem, but I'm not sure how to do it with selenium-webdriver.Basically, the default naming is failing to save the screenshot, because the default file names that get generated are too long, because they use the spec description to create the file. This is the error I'm seein...Read more

Map name of model object to a pg_search query param in Rails 5.1

I have an album model, that has one 'cover_image' and has_many 'images'. I also have a product model. I am using pg_search to filter my products. Independently, they both work flawlessly. What I would like to do is show an albums cover_image based on the pg_search filter param.For example: If I had a filter param called "limestone", I would create an album called "limestone" and when a user filters the page by limestone, they would get the product results along with the matching cover_image.product_controller - this works for filtering def ...Read more

ruby on rails - rake db:migrate error when i'm trying install ratyrate

I tried to install ratyrate. I added it to my Gemfile and ran bundle install Now, after running rake db:migrate, I got this:/var/lib/gems/2.3.0/gems/mime-types-1.25.1/lib/mime/types.rb:36: warning: already initialized constant MIME::Type::VERSION/usr/lib/ruby/vendor_ruby/mime/type.rb:56: warning: previous definition of VERSION was here/var/lib/gems/2.3.0/gems/mime-types-1.25.1/lib/mime/types.rb:40: warning: already initialized constant MIME::Type::MEDIA_TYPE_RE/usr/lib/ruby/vendor_ruby/mime/type.rb:61: warning: previous definition of MEDIA_TYP...Read more

How to test wash_out controller with Rspec in Rails 5

I am using wash_out to create a soap webservice, this is my controller:class SignerController < ApplicationController soap_service soap_action 'xmlSign', args: { xml: :string, certificate: :string }, return: { signed_xml: :string, error: :string }, to: :xml_sign def xml_sign render soap: { signed_xml: "TODO" } rescue render soap: { error: $!.message } endendfollowing http://blog.johnsonch.com/2013/04/18/rails-3-soap-and-testing-oh-my/ I wrote this test:require 'rails_helper'require 'sav...Read more

Rails rollback DB and revert select commits

We have a feature (that contained some DB migrations and 50+ changed files) that was merged into master a few commits ago. The powers that be now want that whole feature removed.There have been no new migrations since this feature was added though there have been some new commits that we want to keep.What's the best way to unwind this quickly, assuming small team and OK to force push to origin? Is it possible (read: recommended?) to: rollback the migrations to the point right before this feature (PR) was mergedrevert the git commits back to the...Read more

Issues with system test setup using Capybara and Selenium on Rails 5.1 app (upgraded from Rails 4)

I'm attempting to set up system tests with Capybara and Selenium on an existing Rails 5.1 (Upgraded from Rails 4) app that already had capybara based feature tests. Here's what I've done so far.In the gem file under group :development, :test: gem 'chromedriver-helper' gem 'selenium-webdriver'gem 'rack_session_access'In the environments/development.rb and environments/test.rb: config.action_mailer.default_url_options = { host: 'localhost:3000' } In the spec\rails_helper.rb: Capybara.register_driver :selenium do |app| Capybara::Selenium::Dri...Read more