ruby-on-rails-5

Find Image of Messaged User associated with chatrooms using Group Chat via Actioncable

主宰稳场 提交于 2020-01-05 05:50:35
问题 Apologies for the basic question. I managed to follow tutorials and with the help of the SO community managed to build a Group Chat with Action Cable and learned loads from doing so. However, I'm trying to pull up on a specific html page - the image of a Messaged User associated with a current_users Chatrooms. I've already been able to pull the chatrooms associated with a current user as well as the last message delivered in those chatrooms. I tried the following but this only gave me the

Rails - Get namespaced constant from Rails configuration

邮差的信 提交于 2020-01-05 05:30:30
问题 Suppose I have several implementations for a search engine. module Searcher module Engine class Elasticsearch end class Algolia end end end I want a per-environment search engine configuration. I declared the config in my environment (for some sort of Bridge Pattern) Rails.application.configure do config.search_engine = :elasticsearch end (Which I override in specific environment files) Then in my search controller, I want to load the appropriate class according to the symbol I put in Rails

Minimagick error during upload “composite -compose Over -gravity North”

霸气de小男生 提交于 2020-01-04 05:46:31
问题 I am trying to upload an image by gem "carrierwave", "~> 1.1.0" and gem "mini_magick", "~> 4.7.0" to upload image. I am getting this error. I am using this code to upload image. MiniMagick::Tool::Convert.new do |i| i.size "#{image_width.ceil}x#{watermarked_image_height.ceil}" i.gravity "center" i.xc "white" i << temp_image_path end @_watermarked_image = MiniMagick::Image.open(temp_image_path) @_watermarked_image = @_watermarked_image.composite(source_image, "jpg") do |c| c.compose "Over" c

Rails Font CORS policy

人盡茶涼 提交于 2020-01-04 02:42:14
问题 I can't load this font for a CORS Policy. Folder : app/assets/fonts/Inter-UI.var.woff2 <%=preload_link_tag("Inter-UI.var.woff2", as:'font', crossorigin: "anonymous")%> Error: Access to font at 'http://localhost:3000/assets/Inter-UI.var-e2e323d19d24946c4d481135af27ba00f3266aa9d4abe4262e97088feccb6ca4.woff2' from origin 'http://0.0.0.0:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Response HTTP status code If I go directly

Ruby super-insensitive Regex to match school names with accents and other diacritics

こ雲淡風輕ζ 提交于 2020-01-04 02:17:26
问题 The question has been asked in other programming languages, but how would you perform an accent insensitive regex on Ruby ? My current code is something like scope :by_registered_name, ->(regex){ where(:name => /#{Regexp.escape(regex)}/i) } I thought maybe I could replace non-alphanumeric+whitespace characters by dots, and remove the escape , but is there not a better way ? I'm afraid I could catch weird things if I do that... I am targeting French right now, but if I could also fix it for

Rails - Using join with custom-named associations

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-03 21:03:05
问题 I have the following model class Measurement < ApplicationRecord belongs_to :examination, class_name: "TestStructure", foreign_key: "examination_id" end The association is actually made to the TestStructure model, but the association name is examination. There is no examination table. The problem arises when I'm querying using join . The following query Measurement.joins(:examination).where(examination: { year: 2016, month: 5 }) fails, with this error ActiveRecord::StatementInvalid: PG:

Render different show pages with category in ruby on rails

99封情书 提交于 2020-01-03 05:07:06
问题 I need render different show pages for my blog posts. I have 3 different categories : themes, snippets, projects. Each blog post must related with those three categories. If anyone click post(assume related category is snippets), it display in different show...etc... It is same for other categories. How it is possible with conditional statements. 回答1: you can make routes like: resources :posts, except:[:show] get 'posts/:id/cat/:category' , to:'posts#show', as: :show you have to create

update action of a RESTful route in Rails (PATCH or PUT)

北城余情 提交于 2020-01-02 08:43:38
问题 I am a newbie to Ruby on Rails.why is the update action of a RESTful route in Rails is mapped to two HTTP verbs i.e, PATCH and PUT? PATCH /articles/:id(.:format) articles#update PUT /articles/:id(.:format) articles#update Which Method among the two is called when I update a resource(general CRUD )? 回答1: It's done to follow HTTP standard for request types. How @Mikhail mentioned, conceptually: PATCH is a proper request type, when you want to update only part of your object PUT is a standard

How can I use Rails 5.2 credentials in capistrano's deploy.rb file?

强颜欢笑 提交于 2020-01-02 02:24:05
问题 I've just updated my Rails app to 5.2, and configured it to use the new config/credentials.yml.enc file. When I try to deploy, I get this error: NameError: uninitialized constant Rails /Users/me/Documents/project/config/deploy.rb:27:in `<top (required)>' That's pointing to this line in my config/deploy.rb file: set :rollbar_token, Rails.application.credentials[:rollbar_token] So it appears that while capistrano is running, it doesn't have access to Rails.application.credentials . How are you

Setup cookie.signed in Rails 5 controller integration tests

这一生的挚爱 提交于 2020-01-01 09:15:13
问题 Imagine the scenario that there is a controller integration test calls a controller method, in which cookie.signed is used for some integrity checking. Controller # app/controllers/foo_controller.rb def index entity = FooEntity.find_by_id(params[:id]) if entity.nil? raise ActionController::BadRequest, 'Could not find requested entity.' else @is_authorized = entity.token == cookies.signed[:token] if @is_authorized # Success! The path to be tested. else raise ActionController::BadRequest,