I have devise gem in my application. I've been playing around with making some tables etc. Now I want to separate the database for the admin and the database for the user. I know its one single database. But, I'm not sure how to get it going in Rails.
jeudi 11 juillet 2019
mercredi 10 juillet 2019
Selenium::WebDriver::Error::UnknownError: invalid argument: can't kill an exited process | Travis webdrivers
I try to build on Travis and launch my user test but I have the following error : Selenium::WebDriver::Error::UnknownError:invalid argument: can't kill an exited process I may use wrong version of firefox and geckodriver but can't figure out what is the right one.. Here is the screenshot of travis interface and my travis.yml file. Thanks a lot !
language: ruby
cache:
bundler: true
yarn: true
directories:
- vendor/bundle
- node_modules
- tmp/cache
- public/assets
services:
- redis-server
sudo: required
addons:
postgresql: '9.5'
chrome: stable
firefox: latest
apt:
packages:
- chromium-chromedriver
- google-chrome-stable
before_install:
- gem install bundler -v 2.0.1
- openssl aes-256-cbc -K $encrypted_67af5a301080_key -iv $encrypted_67af5a301080_iv
-in application.yml.enc -out config/application.yml -d
- sudo apt-get update
- sudo apt-get install google-chrome-stable
- wget https://github.com/mozilla/geckodriver/releases/download/v0.24.0/geckodriver-v0.24.0-linux64.tar.gz
- mkdir geckodriver
- tar -xzf geckodriver-v0.24.0-linux64.tar.gz -C geckodriver
before_script:
- psql -c 'create database simundia_v6_test;' -U postgres
script:
- bundle exec rake db:migrate
- yarn install --production=false
- bundle exec rails assets:precompile
- bundle exec rspec $TESTFOLDER
env:
- TESTFOLDER=spec/features/coach_journey_spec.rb
- TESTFOLDER=spec/features/coached_journey_spec.rb
- TESTFOLDER=spec/features/client_demo_journey_spec.rb
- MOZ_HEADLESS=1
10.87s$ bundle exec rspec $TESTFOLDER
Capybara starting Puma...
* Version 3.12.0 , codename: Llamas in Pajamas
* Min threads: 0, max threads: 4
* Listening on tcp://127.0.0.1:43817
F
Failures:
1) Coach user journey success
Failure/Error: visit '/users/sign_in'
Selenium::WebDriver::Error::UnknownError:
invalid argument: can't kill an exited process
# ./spec/features/utilities.rb:18:in `visit_session_new'
# ./spec/features/coach_journey_spec.rb:17:in `block (2 levels) in <top (required)>'
How do I retrieve a random GET request in Ruby on Rails 5?
I've created my REST API based on Michael Scott from the Office, so far if you go onto the main part of the API it displays all the quotes /api/v1/quotes/ and you can get individual ones if you add an id number such as /api/v1/quotes/5,but I want users to be able to get a random quote when they put in a GET request.
This would preferably be done with an extra part of the URL such as /api/v1/quotes/random.
I've looked at a lot online but I can't figure this out. Do I put my code into the quotes controller and create another function or do I have to put this somewhere else such as routes.db? Also do I put in the SQL function of RANDOM or is there a better and more efficient way to randomise it. My database only has 50 records in it and it's done in mysql2.
Thanks in advance.
It's my first time posting here as usually I hate asking for help as I think I can always figure it out myself but I'm extremely new to Ruby so I'm fairly clueless on how to solve this. If you need me to clarify my question then just let me know.
Ruby Rails equivalent in nodejs
I'm new in NodeJS I wanted to do the equivalent of this code which is coded in Ruby Rails.It is a survey that I must implement with my frontend
class SurveysController < ApplicationController
before_action :authorize, only: [:create, :update, :destroy, :index]
before_action :set_user, only: [:create, :destroy, :index]
before_action :set_survey, only: [:show, :update, :destroy]
# GET /surveys
def index
@surveys = @user.surveys
render json: @surveys
end
# GET /surveys/1
def show
render json: @survey
end
# POST /surveys
def create
@survey = Survey.new(
title: survey_params[:title],
sub_title: survey_params[:sub_title],
questions: survey_params[:questions].to_json,
user: @user
)
mardi 9 juillet 2019
Initialization error expecting one amount seeing another
I'm trying to complete the card shuffle assignment and must use initialize and self in the code. I have defined what rank and suit mean but the program does not recognize that the variables are used, which they are. Then in the initialization, it says I have the wrong number of arguments
I tried changing the name of the items in the initialize code. I split @cards << (self.rank, self.suit) into 2 lines but made no difference. I moved the variable definitions inside the initialize code which helped with some messages but not the all.
This is the whole program
class Card
attr_accessor :rank, :suit
rank = [2, 3, 4, 5, 6, 7, 8, 9, 10, "Jack", "Queen", "King", "Ace"]
suit = ["Hearts", "Diamond", "Clubs", "Spades"]
def initialize(rank, suit)
self.rank = rank
self.suit = suit
end
def output_card
puts "#{self.rank} of #{self.suit}"
end
#def self.random_card
# Card.new(rand(rank, suit))
#end
end
class Deck
attr_accessor :rank, :suit
#Generates the 4 suits of cards in each denomination
def initialize(cards)
cards = Card.new("rank", "suit")
@cards = []
@cards << Card.new(self.rank, self.suit)
end
#shuffles the deck of cards
def shuffle
unless @cards.empty?
@cards.shuffle!
end
end
#def self.top_card
#Card.new(self.rank, self.suit)
#end
#Deals the cards from the top of the virtual deck.
def deal
@cards.each do |card|
card.output
end
end
end
deck = Card.new
deck.shuffle
deck.deal
This is the current error message I get.
Shannons-MacBook-Air:Desktop leighrachal$ Ruby -w Card.rb
Card.rb:3: warning: assigned but unused variable - rank
Card.rb:4: warning: assigned but unused variable - suit
Card.rb:6:in `initialize': wrong number of arguments (given 0, expected 2) (ArgumentError)
from Card.rb:53:in `new'
from Card.rb:53:in `<main>'
Can stand-alone Rails server accept requests on multiple IP addresses
I want to know if I can launch a Rails server (Puma or otherwise) with options that will allow it to be hit over any IP address (127.0.0.1, localhost, network IP address, etc).
I think -b option only takes one IP address (not a wildcard or anything), and I have to restart it changing that option to allow connections over various IP addresses.
rails s -b 127.0.0.1 -p 3000
I would like to hit my server via both a browser on my machine and a browser on my iPhone on my network, and possibly a browser in a VM on my machine.
lundi 8 juillet 2019
How to use rails update method for multiple object with collection
I am trying to update multiple objects with rails update method with update collection object as following codes:(couldn't really find the collection method)
def update
@reiew = Review.find(reivew_params)
review.update!(reivew_params)
if @reivews.update(reivew_params)
respond_to do |format|
format.html { redirect_to reivew_path}
end
else
respond_to do |format|
format.html { notice: 'saved errors'}
end
end
end