vendredi 3 novembre 2023

Why do I get NoMethodError: undefined method `rescue' for #

Ruby's Concurrent::Future was not catching the exceptions. So I copied the code from an article to add a rescue block. But now I got the error:

Caused by NoMethodError: undefined method `rescue' for #Concurrent::Future:0x0000000124764268

Here is the code:

executed_future = Concurrent::Future.execute do
            url = "#{endpoint}#{datum[:hierarchy_id]}#{valuation_date}"
            raise StandardError.new("Testing error!") # To test

            [...]
          end.rescue do | exception | # Adding this, will throw the error
            @exceptions << exception
            binding.pry # No activated
          end

What am I missing?

I expect to rescue exceptions in the Concurrent::Future block. Just like the article does.

mardi 31 octobre 2023

undefined method `to_model' for #

<%= form_with(model:[@single_room, @message] , remote: true, class: "d-flex" ) do |f| %> <%= f.text_field :body, id: 'chat-text', class: "form-control ", autocomplete: 'off' %> <%= f.submit data: { disable_with: false }, class: "btn btn-primary" %> <% end %>

why it is coming like this

lundi 30 octobre 2023

Mailgun Showing Variable Names as it is Ruby on Rails

I have a template field in my object in which i store the whole email template and store it like below "<p><span style=\"font-family: -apple-system, system-ui, &quot;Segoe UI&quot;, Roboto, Oxygen-Sans, Ubuntu, Cantarell, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;\">%recipient.email%<b><br></b></span><b>&nbsp;<br>&nbsp;</b><span style=\"font-family: -apple-system, system-ui, &quot;Segoe UI&quot;, Roboto, Oxygen-Sans, Ubuntu, Cantarell, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif;\">%recipient.tier_name%</span></p>" in this %recipient.email% is my variable and it will changed by mailgun automatically but the issue is sometimes it does not reflect and appear as it is in the email with out changing its actaul value

example: If recipient.email = test@gmail.com but in email it is showing %recipient.email% instead of test@gmail.com

I want to apply the variable values instead of its variable names. example: If recipient.email = test@gmail.com but in email it is showing %recipient.email% instead of test@gmail.com

def self.send_emails(subject:, html:, to_emails:, recipient_variables: {}, force_send: false, sender_email)
payload = {
  from: sender_name(sender_email),
  subject:,
  html:,
  'recipient-variables': recipient_variables.to_json,
  'o:tag': [subject, tag]
}
esponse = RestClient.post(mailgun_api_url(sender_email), payload)

end

vendredi 27 octobre 2023

Error (Could not find the inverse association for profile_image_attachment (:record in ActiveStorage::Attachment)):

In my model/active_storage/attachment.rb file i had used this code

class ActiveStorage::Attachment < ApplicationRecord belongs_to :blob, class_name: "ActiveStorage::Blob" def self.ransackable_attributes(auth_object = nil) ["blob_id", "created_at", "id", "name", "record_id", "record_type"] end end "When creating Active Admin with Active Storage, I encountered a search error. To address this, I used defined the ransackable method in my model." in my model/user.rb i had used has_one_attached :profile_image when i open this link http://127.0.0.1:3000/users/1 it show this error unknown keywords: :class_name, :as, :inverse_of and when i open this link http://127.0.0.1:3000/admin it open successfullyenter image description here

i had used inverse of in my model/user.rb file , but it did't work i had go through all my schema file it generate activestorage of correctlly.

jeudi 26 octobre 2023

ActiveRecord::InverseOfAssociationNotFoundError in rails 7

Hii in my rails application when I going to open the profile page the following error comes My ruby version is "3.2.2" and my rails version is "7.0.8"

ActiveRecord::InverseOfAssociationNotFoundError in Users#show

Showing /home/nitish/Documents/Bestristey/app/views/users/_user_profile_image.html.erb where line #3 raised:

ActionView::Template::Error (Could not find the inverse association for profile_image_attachment (:record in ActiveStorage::Attachment)):

        1: <div id="profile_image">
        2:     <div>
        3:         <% if user.profile_image.attached? %>
        4:         <%= image_tag(user.profile_image, class: "d-block ui-w-80 " ) %>
        5:         <% else %>
        6:         <img src ="/assets/dummy profile.jpg" alt class="d-block ui-w-80 rounded-circle">

This is the code of my user model:-

class User < ApplicationRecord

      after_create :after_confirmation
  
      devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :validatable,
         :confirmable, :trackable
            
      validates :username, presence: true, uniqueness: true

      has_one_attached :profile_image

      attr_accessor :login
  
      def login
        @login || self.username || self.email
      end
     end


And this is the code from my models/active_storage/attachment.rb file:-

`
class ActiveStorage::Attachment < ApplicationRecord

        belongs_to :blob, class_name: "ActiveStorage::Blob", inverse_of: :attachment

    
  
        def self.ransackable_attributes(auth_object = nil)
          ["blob_id", "created_at", "id", "name", "record_id", "record_type"]
        end
  
      end

I have tried of using :inverse_of in the users model has_one_attached association but then it gives argument error. I also tried some other stuffs also but still no any progress.

mercredi 25 octobre 2023

dyld[4255]: missing symbol on Apple M2

I am running ruby on rails project on my apple M2. Ruby version is 2.5.5. I have done setup using rosetta. After installing all the dependencies when i try to run the console i.e. rake c. I get this error

dyld[4255]: missing symbol called [1] 4255 abort rake c

I have tried removing the old ruby and starting this process from scratch. Have also installed brew using rosetta.

Does anyone know how to solve this?

lundi 23 octobre 2023

Calling a Static Method from a Controller and Updating instance of that class - Getting undefined method for AR::Association::HasOneAssociation

My Question:

What should the correct structure be? I have tried redesign this several times but keep getting tight-coupling issues.

Relevant Info:

I am writing a new endpoint for some third party software. It will receive a payload that I am then passing into a static method of my Subscription class. From there I want to do a look-up of the payload related subscription, establish an instance of it, then perform an update based off the rest of my information on my class. I am running into an error that is saying the following: undefined method update for ActiveRecording::Association::HasOneAssociation

EndPointController:

class Api::V2::EndpointController < Api::V5::BaseController
    def connect
        data = decode(request.body.read)
        Subscription.static_method(data)
    end
end

Subscription Model:

class Subscription < ActiveRecord::Base

    def self.static_method(data)
        @subscription = Subscription.find_by_id(data.subscription_id)
        @subscription.update(data)
    end
end

Subscription Controller:

class SubscriptionsController < ApplicationController
    def update
        #execute update
    end
end