ruby-on-rails-5

How do I select either a th or a td from a table row?

五迷三道 提交于 2019-12-13 07:58:54
问题 I'm using Nokogiri with Rails 5. How do I select either a "th" element or a "td" element from a table row? My goal is to get all the text of cells in a row (if there is a more generic, elegant solution, I'm all in). Here's what I have text_all_rows = all_rows.map do |row| row_values = row.css('td | th').map{|str| str.text } .map{|str| str.gsub(/[[:space:]]+/, ' ').gsub(/\A\p{Space}+|\p{Space}+\z/, '') }.join("\t") [*row_values] end As you may have noticed "td | th" is not valid syntax for

Why does Rails not recognise project_path

回眸只為那壹抹淺笑 提交于 2019-12-13 07:23:35
问题 I wonder if anyone can help with this...its driving me crazy. Firstly I'm still pretty new to all of this. So apologies if I get some terminology wrong. I have completed some tutorials and am now working on my first app without any guided walkthroughs... its slow going :) I have two groups of pages, one group where I should show a sidebar and one group that does not need it. Below are my routes... Rails.application.routes.draw do #----Pages---- root 'pages#home' get '/home', to: 'pages#home'

Passed parameters not being read in Rails

試著忘記壹切 提交于 2019-12-13 06:49:11
问题 I posted this question earlier: Passing parameters on button click in Rails And the answer works very well. However, I the passed parameters aren't able to be called in erb, even the @event_option_id that is being passed from the book_now method. It is showing in my server logs as Parameters: {"event"=>"4", "event_option_id"=>"5"} but when I try to use <%= @event_option_id %> it comes back blank, and when I just tested it as to_i , it showed 0 instead of 5 . My EventsController has this

How to eager load associations into an instance variable?

这一生的挚爱 提交于 2019-12-13 06:46:54
问题 In Model I have: class CalendarItem < Resource belongs_to :schedule has_many :people has_many :documents acts_as_list scope: :schedule, column: :visual_position validates :schedule, :title, presence: true end Then in controller: class ScheduleController < ApplicationController def show @calendar_items = CalendarItem.where(schedule: @schedule).includes(:people, :documents) end ... end In the view I'm rendering a react_component with react-rails (but that should make any difference): = react

Increase ActiveModel ID Range to 8 byte

喜欢而已 提交于 2019-12-13 06:39:20
问题 I've been digging around to see how I could have all my newly and subsequent Model id's to have a limit of 8 byte. Answers show how to when adding a new table column; I want whenever I create a new Model , it would automatically has a limit of 8 byte. Possible? When creating a new model, I get: ActiveModel::RangeError: 36565651767 is out of range for ActiveModel::Type::Integer with limit 4 Where to change this limit from 4 to 8? 回答1: A possible duplicate but since there will be errors: you

Error Deploying on Elastic Beanstalk - Rails

一世执手 提交于 2019-12-13 06:30:05
问题 I'm trying to deploy a custom project on Elastic Beanstalk but I'm getting the following error in my puma.log file when puma is started. I'm not sure how to fix this. I assume it might be with my yaml parser but I'm not entirely sure how to update that using EB. Any help would be appreciated. === puma startup: 2018-12-26 22:06:02 +0000 === /opt/rubies/ruby-2.5.3/lib/ruby/2.5.0/psych.rb:402:in 'parse': (<unknown>): did not find expected alphabetic or numeric character while scanning an alias

Making a calculation for a modal using coffeescript

北战南征 提交于 2019-12-13 03:58:15
问题 I am trying to make it so a user can input 3 numbers and when they click the submit button they will see a modal with the calculations from these 3 numbers within the modal. I am unsure how to accomplish this. I have the calculation in my controller. class WelcomeController < ApplicationController def how_much @price = (params[:amount]) @mortgage = (params[:high_rent]) @rent = (params[:current_rent]) if @price && @mortgage && @rent.present? @monthly_savings = @mortgage - @rent @savings_goal =

Ruby reverse.each_with_index and delete_at causing problems in latest Ruby/Rails

拥有回忆 提交于 2019-12-13 03:50:38
问题 So, I'm well aware of the perils of removing items in an iteration block (this is looping in reverse), and I know Matz mentioned something about mutations in iterations causing stability problems, but I can't seem to figure this one out. This example is a little convoluted and I'm not sure even solving it will replicate the example exactly, but I'll have to try. arr1 = [1, 2, 3, 4, 5] arr2 = [3, 4, 5] puts arr1.inspect puts arr2.inspect arr2.each do |i| arr1.reverse.each_with_index do |j,

Why are parameters not being passed within my test in Rails 5?

旧街凉风 提交于 2019-12-13 03:49:33
问题 I have the following code in users_controller.rb : def create params = user_params x = 1 render :json => { :message => "New user created!"}, :status => :ok end private def user_params params.permit! end It obviously doesn't do much right now. I don't have any before or after filters on it. I also have the following test code: RSpec.describe UsersController, type: :controller do fixtures :users, :clients include AuthHelper before do @request.headers["Content-Type"] = 'application/json'

Rails Webpack fingerprinting not working as intended

允我心安 提交于 2019-12-13 03:49:27
问题 I've been using mostly vanilla Webpack configuration with Vue.js. I've been trying to trackdown what broke it, but my fingerprinting doesn't seem to work well anymore. Everytime I update one of the components, a pack would get reloaded, as you'd expect. The problem is that on production, browser doesn't seem to know about it anymore. So it will try to use the old pack, not find it and crash my app. Only by clearing the cache to make it download all packs again, it will get the pack with the