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

how to debug gitlab-ce docker container?

My environment: osx14.0 rubymine gitlab-ce 16.4

I want to debug gitlab-ce remotelly with local rubymine on my mac. I expose 3000 in the docker container, but rubymine cannot debug it on 3000 port directly. I am more familiar to Java and PHP, but new to ruby thanks!

I tried to use rubymine connect to 3000 port on the docker container, but I failed

jeudi 19 octobre 2023

Update Database in Ruby on Rails version 7.11

Hello community I am new to ruby on rails, I have a problem with updating the database, when I try to update a record, all records are updated

this is my article_controller this is my router

I was reviewing the documentation and I saw that I do it similarly, I have searched for information on the internet and I can't find a solution

I want to update only one record by passing the id

mardi 3 octobre 2023

How to authenticate and access the Gmail API in Ruby without using OOB

How do I connect to the api without using oob since it is obsolete, I have been searching and I can't find any example. Alguna ayuda

These are the methods for OOB but I don't need to use them as they are deprecated.

type here
require 'googleauth'
require 'googleauth/stores/file_token_store'
require 'google/apis/gmail_v1'

# Constants for authentication
OOB_URI = 'urn:ietf:wg:oauth:2.0:oob'.freeze
APPLICATION_NAME = 'Your Gmail Application'
CLIENT_SECRETS_PATH = 'path/to/client_secrets.json'.freeze
CREDENTIALS_PATH = 'path/to/credentials.yaml'.freeze
SCOPE = Google::Apis::GmailV1::AUTH_SCOPE

# Configure authentication
client_id = Google::Auth::ClientId.from_file(CLIENT_SECRETS_PATH)
token_store = Google::Auth::Stores::FileTokenStore.new(file: CREDENTIALS_PATH)
authorizer = Google::Auth::UserAuthorizer.new(client_id, SCOPE)
credentials = authorizer.get_credentials('user_id', token_store)

Step 2: Credential Verification
In this step, we'll check if we already have stored credentials or if we need user authentication.

# Check if credentials exist or if user authentication is needed
if credentials.nil?
  url = authorizer.get_authorization_url(base_url: OOB_URI)
  puts 'Open the following URL in your browser and enter the authorization code:'
  puts url
  code = gets
  credentials = authorizer.get_and_store_credentials_from_code(
    user_id: 'user_id', code: code, base_url: OOB_URI, token_store: token_store
  )
end