ruby-on-rails-5

Getting “cannot load such file — rack/handler/--debugger (LoadError)” when trying to start Rails server in debug mode

早过忘川 提交于 2021-01-29 15:09:50
问题 I'm using Rails 5 and Ruby 2.4. I want to start my server in debug mode so that I can debug in my IDE (Aptana Studio). I tried the below but get the error ... localhost:ruby-angular-app davea$ rails server --debugger Exiting /Users/davea/.rvm/gems/ruby-2.4.0/gems/rack-2.0.7/lib/rack/handler.rb:74:in `require': cannot load such file -- rack/handler/--debugger (LoadError) from /Users/davea/.rvm/gems/ruby-2.4.0/gems/rack-2.0.7/lib/rack/handler.rb:74:in `try_require' from /Users/davea/.rvm/gems

Rails 5.2.1 - Model & Fragment Caching

和自甴很熟 提交于 2021-01-29 09:23:20
问题 I am trying to setup Model and Fragment Caching in Rails 5.2.1 I have had success with Fragment caching, but I am still seeing database queries after implementing model caching for my Model. I have enabled development caching $ rails dev:cache Model Helper module LanguagesHelper def approved_languages Rails.cache.fetch("approved_languages") { Languages.is_active.is_approved } end end Controller class LanguagesController < ApplicationController include LanguagesHelper def index @languages =

How to push a dockerized project on heroku

限于喜欢 提交于 2021-01-29 08:20:53
问题 hope you are fine! Actually, I have a dockerized rails API I'm working on.& I have to push it on Heroku. I add pg gem to my production environment & move MySql gem to the development environment group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a console gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] # Adds support for Capybara system testing and selenium driver gem 'capybara', '~> 2.13' gem 'selenium-webdriver' gem 'mocha' gem 'webmock' gem

rails http response to Donwload excel file

女生的网名这么多〃 提交于 2021-01-29 07:45:52
问题 i saw this code in github require "csv" csv_str = CSV.generate do |csv| csv << ["awesome", "csv"] end result = IO.popen("secure-spreadsheet --password secret", "r+") do |io| io.write(csv_str) io.close_write io.read end File.open("output.xlsx", "w") { |f| f.write(result) } this code store a Excel file(output.xlsx) in my project file. how can i convert this "store file scenario" in to "download the file in the browser"? 回答1: In your config/initializers/mime_types.rb register the xlsx mime_type

How to skip logging uncaught exceptions in Rails?

你说的曾经没有我的故事 提交于 2021-01-29 07:21:21
问题 When using custom exceptions_app and rescue_responses , an application has more control of uncaught exceptions and an excessive logging from DebugExceptions middleware becomes noise. As an example, the application knows how to process ActionPolicy::Unauthorized , renders proper page in exceptions_app and thus the following log is redundant: FATAL -- : FATAL -- : ActionPolicy::Unauthorized (Not Authorized): FATAL -- : FATAL -- : app/controllers/topics_suggest_controller.rb:47:in `topic_load'

Rails - Pundit - how to check for current_admin_user?

送分小仙女□ 提交于 2021-01-29 06:36:56
问题 I am using Pundit for authorization for my User model. My goal is to extend this to use my AdminUser model, specifically for my admin namespace. By default, Pundit checks for a "user" or "current_user". How can I change this to check for a "admin_user" or "current_admin_user", based on Devise? policies/admin/admin_policy.rb (Closed system, currently looks for User instead of AdminUser) class Admin::AdminPolicy attr_reader :user, :record def initialize(user, record) # Must be logged in raise

rbenv: rails: command not found immediately after installing rails 5.2.1

此生再无相见时 提交于 2021-01-29 04:55:38
问题 I have spent the whole day trying to upgrade from Rails 4x to 5.2.1. I was following this guide for the upgrade and I was not able to upgrade successfully. Issue: After "successfully" installing Rails 5 using: ruby 2.5.3p105 (2018-10-18 revision 65156) [x86_64-darwin17] and did rails -v I get: rbenv: rails: command not found The `rails' command exists in these Ruby versions: 2.2.0 Things that I have tried: gem pristine different gems gem pristine --all this and played around with paths but no

Conditional class in slim with 3 conditions

六月ゝ 毕业季﹏ 提交于 2021-01-28 22:17:43
问题 I would like to write conditional class in slim but I only know how to do it with 2 conditions, like : div class=(index == 0 ? 'class1' : 'class1 class3') How to do it with three conditions? - if index == 0 .class1 - elsif index == -1 .class2.class3 - else .class1.class3 回答1: div class=(if index == 0 then 'class1' elsif index == -1 then 'class2 class3' else '.class1 class3' end) 来源: https://stackoverflow.com/questions/40591084/conditional-class-in-slim-with-3-conditions

Rails, render_async gem: How to use render_async inside a partial that is loaded via ajax

只谈情不闲聊 提交于 2021-01-28 11:21:51
问题 Problem I'm using the gem "render_async" to render content asynchronously. When I visit a page like localhost:3000/people , the content gets rendered asynchronously, as expected. However, the content does not get rendered asynchronously, if it is inside a partial that got loaded via ajax. I don't understand why it isn't working and I don't know how to fix it. How can I use render_async, if it is inside a partial that got loaded via ajax? gem render_async: https://github.com/renderedtext

Adding an image_tag for the inline background-image url in Rails 5 template

余生颓废 提交于 2021-01-28 10:44:13
问题 I need to set the background image inline using the style tag, but it needs to reference an image object and not a fixed image from the assets folder. Below is my code to show what I am attempting to do. <div class="background-image-holder" style="background: url(#{" image_path @product.photo_one_url(:original)"}); opacity: 1;"> <%= image_tag(@product.photo_one_url(:medium)) %> </div> 回答1: I always prefer to use a content_tag if I'm including something dynamic like this, i.e. <%= content_tag