Is there a better way to access CanCanCan's methods such as can? in a model?
CanCanCan’s methods are only available in a controller or view, but I want to access them in a model, more specifically in a model’s save method. The workaround I use for this is the following: I...
View ArticleCan't change Ruby Version with RubyMine Terminal
I have a weird problem with the terminal in RubyMine. In my previously created project, RubyMine worked fine, the project ruby version is automatically set at 3.2.3 after using rails new. For some...
View ArticleIs there any method to execute whenever scheduled jobs only when i run "rails...
I create a whenever scheduled task + ActiveJob job.I configure config/initializers/scheduler.rb like this:Rails.application.config.after_initialize do ScheduleJobManager.new # 创建定时任务endThis job will...
View ArticleWhen using a Hash as a ERB templates, ruby complains about "encoding"
Simply to thatrequire 'erb'a = "aixòés una merda <%=rand(1..20)%>"c = {"id" => "aixòés una merda <%=rand(1..10)%>"}If you run ERB.new(a).result, then all is fine:ERB.new(a).result=>...
View Articlebundle install is hanging when installing gems
I'm trying to install Canvas LMS on an Ubuntu 22.04 system.I've tried running bundle install on the required gems as given by Canvas LMS.This is the output I get:Resolving dependencies...Fetching...
View ArticleWhat : means in ruby
How constructionprocess resize_to_limit: [400,400] works?is process is a function? Why : after resize_to_limit?Why [400,400] after :?Library:...
View ArticleSet ActiveSupport cache_format_version when not using rails
I have a small application that uses ActiveSupport::Cache (via require 'active_support/cache'), and is not a full rails application. How do I set the cache.active_support_cache_format_version to solve...
View ArticleImage not displaying in Wicked PDF generated PDF in Rails
I'm facing an issue where the image border is being displayed in the PDF generated by Wicked PDF in my Rails application, but the actual image content is not showing up. I've confirmed that the images...
View ArticleHow to get the current route in rails
I am building some rails sample application in which I am having two models User and Projects. Association between both is user has_many projects. Now the question is I am willing to provide some drop...
View ArticleRails: How to change the title of a page?
What is the best way to create a custom title for pages in a Rails app without using a plug-in?
View Articlestatic website with Jekyll: bundler: failed to load command: jekyll
running bundle exec jekyll serve ....I get this (the project is a clone of one I already made...jekyll static website)do I need some new or old version of jekyll, ruby, or some gem issue?tried a ton of...
View ArticleEvaluate YAML elements with ERB syntax
I have a YAML which includes some ERB blocks:---- id: "1" pre: |<% a = rand(2..20) b = rand(1..20) %> sentence: "The result of <%=a%> +<%=b%> is <%=a+b%>"- id: "2" pre: |<% a...
View ArticleHow to get the full URL with the current path in Capybara
I'm new to writing tests in capybara and I'm having trouble getting the current URL of a page. I wrote it like this:url = page.current_url + page.current_pathSomehow its just returning the base URL....
View ArticleChange format of datepickr calendar to 24 hr format
I am using datepickr in my rails application on active admin side which is when selecting time from the pickr I get 12 hr format but I want 24 hrs format in the calendar.Is there any way to change...
View ArticleWSL 2 Ubuntu cannot load such file -- zlib
I just got an old project. But when I run bundle install command from the guide, I got this error.irwan@LAPTOP-3KM80MDK:~$ gem install bundler:1.9.0 ERROR: Loading command: install (LoadError)cannot...
View ArticleUnexpected Behavior with Array#select and nil Values [closed]
So, I've been chilling with some Ruby code, trying to brush up on my skills, and I've hit a weird snag that's kind of bugging me. I was playing around with Array#select, trying to filter out nil values...
View ArticleWhat does the "$" character mean in Ruby?
Been playing with Ruby on Rails for awhile and decided to take a look through the actual source. Grabbed the repo from GitHub and started looking around. Came across some code that I am not sure what...
View ArticleBundle install failed for mysql2 gem
I updated my local machine mysql from 5.7 to 8 and after installing it couldn't install DB Adapter mysql2 gem via bundle install command.However, i am able to install it with the following command.gem...
View Articleerror: call to undeclared function 'ffi_prep_closure'; I...
I am usingrvm install ruby-2.7.1 to install ruby for mac M1 but the above error appears and the installation process has stopped, how can I fix the error, please help me, thank you...
View ArticlePrepend Kernel module function globally
I want to prepend Kernel.rand like this:# I try something likemod = Module.new do def rand(*args) p "do something" super(*args) endendKernel.prepend(mod)# And I expect this behaviourKernel.rand #>...
View Article