dimanche 29 septembre 2019

Active record lookup - find_by_inventory_product_id is intermittently slow inspite of adding index

I have a simple new API endpoint, which involves querying my newly setup and populated table - inventory_products.

The schema of inventory_products table is :

CREATE TABLE `inventory_products` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `inventory_product_id` binary(16) DEFAULT NULL,
  `product_id` binary(16) DEFAULT NULL,
  `status` enum('ACTIVE','INACTIVE','DELETED') DEFAULT 'ACTIVE',
  `priority` int(11) DEFAULT '0',
  `inventory_service_id` tinyint(3) DEFAULT NULL,
  `created_at` datetime DEFAULT NULL,
  `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uc_inventory_product_id` (`inventory_product_id`),
  KEY `idx_product_status` (`product_id`,`status`)
) ENGINE=InnoDB AUTO_INCREMENT=76312817 DEFAULT CHARSET=utf8;

The API endpoint mainly does the below:

def lookup_inventory_service_id
    return render_error_response(AUTH_ERROR, {status: 403}) unless client.name == PERMITTED_NAME

    ip_fetch_start = Time.now
    inventory_product = InventoryProducts.find_by_inventory_product_id(resource_attributes[:inventory_product_id])
    Rails.logger.info({inventory_product_id: resource_attributes[:inventory_product_id], inventory_product_fetch_time_ms: (Time.now - ip_fetch_start)*1000}.as_json)
    return head :not_found unless inventory_product
....

Problem: The inventory_product lookup (find_by_inventory_product_id) is the standard function provided by Rails's ActiveRecord (I have not overwritten it in my model). This function takes from 10ms to sometimes even 650ms (found this from the logs I added). Why would this take up so much time in some cases and so less time in some other in spite of Mysql index existing on the column used in the lookup?

I have mentioned inventory_product_id as a unique key in my schema and the MySQL query triggered by the above function is using inventory_product_id as an index from the below explain statement.

explain SELECT inventory_products.* FROM inventory_products WHERE inventory_products.inventory_product_id = 0x3a288cdce78d44618eadd72e240f26a4 LIMIT 1

id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE inventory_products const uc_inventory_product_id uc_inventory_product_id 17 const 1 NULL

Is there something wrong in my schema? Do I explicitly need to mention inventory_product_id as a mysql index in the schema? Something like:

KEY `idx_product_status` (`product_id`,`status`)

Thanks, in advance!!

I use Mysql 5.6 and rails - 3.2.8. Also, my rails application runs on a tomcat server (version - Apache Tomcat/7.0.16) inside jruby (1.7.0)/

jeudi 26 septembre 2019

reading file contents from git remote in ruby code

Is it possible to read file form git remote origin without cloning repository in ruby code.?? What I tried is cloning the whole repository into my system and then reading the file, but cloning repository is very time consuming.Is there any way to avoid cloning the repository.

I accidentally clicked on some source code, and now I get this weird text in my GitBash terminal. How can I fix this?

I clicked a file called "provision.sh" that was listed as a resource on my class's website, and it opened my GitBash terminal and started running some script, before terminating the GitBash window. Now, when I open GitBash, and try simple commands such as "cd ", it will still open the directory but it spits out the text "which:no bundle in (c/Users/my_user_name/bin:mingw64/bin::/usr/bin:/bin:/mingw64/bin:/usr/bin:/c/Users/my_user_name/bin:/c/Program Files (x86)/Java/jdk1.8.0_161/bin:/c/Users/my_user_name/AppData/Local/Microsoft/WindowsApps:/c/HashiCorp/Vagrant/bin:/usr/bin:/c/Program Files (x86)/Java/jdk1.8.0_161/bin:/c/Users/my_user_name/AppData/Local/Microsoft/WindowsApps:/c/Program Files (x86)/Git/usr/bin:/c/Program Files (x86)/Heroku:.:/usr/bin/vendor_perl:/usr/bin/core_perl:/c/Users/my_user_name/.rvm/bin:/c/Python27)".

It does this after every command and I would really like to figure out how to reverse this.

I've tried checking my CLASSPATH and environmental variables, but I don't really know what I'm looking for. I also tried opening the Task Manager and checking if any weird processes are running, but I don't see anything. Please help!

Exclude active record entries based on another active record attribute

(feel free to change the headline to what may be more suitable)

I am using Ruby on Rails and I have two model sets:

  • Page
  • Store

  • A page has_many stores.

  • A store has the attribute status_nbr which ranges from 1-5.

For example, page #1 could have 5 stores where two of them have status_nbr = 1 and three of them have status_nbr = 3.

I want to run a query which to find all Pages where there is no store who has status_nbr = 1. In other words, Pages that lack stores with status_nbr = 1. How do I do that? I assume this can be done with some clever join?

As for now I run a loop:

ok_list = []
Page.all.each do |page|
  ok_list << page.id unless page.stores.where(:status_nbr => 1).blank?
end
@pages = Page.where(:id => ok)

which is very bad/slow programming.

Edit: This is not a duplicate question of the one referred. My model is dependent on another model and the attribute of that other model.

mercredi 25 septembre 2019

Confused on how to setup Geokit

So I've searched through all the documentation on Geokit for rails and didn't find any setup process for it except for installing the gem which I know how to do. what tables do I add to an existing "listings" table?

I've like I said, have it installed. And I've added the acts_as_mappable to the listings ruby file.

class Listing < ApplicationRecord
  acts_as_mappable
end
gem 'geokit-rails'

It would be nice if there was a video tutorial done on how to set this entire thing up.

mardi 24 septembre 2019

Stop rails controller method execution if xhr request is cancelled? Rails API

I'm trying to create an SPA with react frontend and a rails API, and I managed to stop the request from the javascript side, with that in mind, I notice that even if I cancel the request, the rails server stills performs the stuff inside the controller.

    def index
      @dashboards = Dashboard.all
      # Rest of controller logic, like calls to an external API

      render json: json_response(@dashboards)
    end

Is there a way to catch that the xhr request was cancelled so I can do something like this:

    def index
      @dashboards = Dashboard.all
      if request.cancelled? throw :abort 
      # It should not matter since request was cancelled in the frontend

      render json: json_response(@dashboards)
    end

lundi 23 septembre 2019

Couldnt upload xls files by using Shrine Uploader

I can upload many files including pdf etc, however could not upload xls files. I get a rollback error like File type must be one of(mime types that are in my shrine_uploader.rb) ['image/jpg', 'image/jpeg', 'image/png', 'image/gif','image/tiff', 'application/pdf', 'application/msword', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/vnd.ms-excel', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/vnd.ms-powerpoint', 'application/vnd.openxmlformats-officedocument.presentationml.presentation', 'application/vnd.oasis.opendocument.spreadsheet ods', 'application/vnd.oasis.opendocument.spreadsheet-template ots']

Thanks for your answers.

dimanche 22 septembre 2019

How to make images not to be cached after update?

I am using ruby on rails building my rest api for my SPA site. I used to use the Rails asset helpers (image_tag, stylesheet_link_tag, etc) do this automatically. I wonder how to do it automatically for my rest api. Thanks.

vendredi 20 septembre 2019

to_model delegated to attachment, but attachment is nil

So I asked this question already here: previous question and didn't get much help, I looked for other questions similar to mine, but no resolution. So I'll ask the question again in hopes of getting help. The issue is that the image that is uploaded for a user profile banner isnt showing on the user show page aka profile page. I'm using active storage. I already have the

has_on_attached :banner_image

.profile-header
  = image_tag url_for(@user.banner_image)

def set_user
  @user = User.find(params[:id])
end

devise registration config:

def configure_account_update_params
  before_action :configure_account_update_params, only: [:update]
  devise_parameter_sanitizer.permit(:sign_up, keys: [:firstname, :banner_image])
end

error msg image

How to Configure CORS Accept Headers in Rails

i am trying to configure CORS accept headers in rails that when i did as below it doesnt seem to allow me to do so as it will threw back this 404 with the OPTIONS request

application controller

class ApplicationController < ActionController::Base
  before_action :set_paper_trail_whodunnit, :cors_set_access_control_headers
  skip_before_filter :verify_authenticity_token

  def verify_api_key
    return if request.headers["HTTP_API_KEY"] == Rails.configuration.x.api_key
    render json: { status: :unauthorized }, status: :unauthorized
  end
def cors_preflight_check
  if request.method == 'OPTIONS'
    cors_set_access_control_headers
    render text: '', content_type: 'text/plain'
  end
end

protected

def cors_set_access_control_headers
  response.headers['Access-Control-Allow-Origin'] = '*'
  response.headers['Access-Control-Allow-Methods'] = 'POST, GET, PUT, PATCH, DELETE, OPTIONS'
  response.headers['Access-Control-Allow-Headers'] = 'Origin, Content-Type, Accept, Authorization, Token, Auth-Token, Email, X-User-Token, X-User-Email'
  response.headers['Access-Control-Max-Age'] = '1728000'
end
end


application.rb


    config.action_dispatch.default_headers = {
    'Access-Control-Allow-Origin' => '*',
    'Access-Control-Request-Method' => %w{GET POST OPTIONS}.join(","),
    'Access-Control-Allow-Methods' => %w{GET POST OPTIONS}.join(",")
}


can anyone help?

mercredi 18 septembre 2019

Rails Active Storage not display @user.banner_image

So I've been playing with rails active storage lately and came across an issue.

user.rb

class User < ApplicationRecord
  has_one_attached :banner_image
end


show.html.haml

.profile-header
  = @user.banner_image

in return i get this error:

Can't resolve image into URL: to_model delegated to attachment, but attachment is nil
Extracted source (around line #2):

.profile-header
  = image_tag @user.banner_image

.listings
  - @listings.each do |listing|
    .box


What am I doing wrong? I permitted the banner_image in the user controller by the way. and i have active storage installed.

mardi 17 septembre 2019

Ruby: How can write emojis in an input field?

I am trying to make a bot that reads lines with emojis and then write them on an input field on browser but it seems that emojis are not supported . My terminal supports emojis but when i write them on input field it shows a bunch of words. How can i do this ??

lundi 16 septembre 2019

Accessing a hash inside an array

I am working on a coding problem where I have 3 lines of text and I have to calculate the words that appear the most in those lines. The answer is: ['it','really','will'] because the text is:

This is a really really really cool experiment really Cute little experiment Will it work maybe it will work do you think it will it will

Everything works in the code below except the highest_count_words_across_lines method. It's supposed to return ['it','really','will'] but instead returns 2 hashes inside an array:[{"a"=>1, "cool"=>1, "experiment"=>1, "is"=>1, "really"=>4, "this"=>1}, {"cute"=>1, "experiment"=>1, "little"=>1}, {"do"=>1, "it"=>4, "maybe"=>1, "think"=>1, "will"=>4, "work"=>2, "you"=>1}].

I've tried iterating through a hash with multiple select statements to no avail.

This is my full code so far:

class LineAnalyzer
      attr_accessor :highest_wf_count, :highest_wf_words, :content, :line_number #Implement the following read-only attributes in the LineAnalyzer class. 

  def initialize(content, line)   
      @content = content   #* initialize the content and line_number attributes
      @line_number = line   
      @highest_wf_count = 0
      calculate_word_frequency()  
  end

  def calculate_word_frequency()
    @highest_wf_words = Hash.new
    words = @content.downcase.split
    words.each { |w|
      if @highest_wf_words.has_key?(w)
        @highest_wf_words[w] += 1
      else
        @highest_wf_words[w] = 1
      end
    }
    @highest_wf_words.sort_by { |word, count| count }
    @highest_wf_words.each do |key, value|
      if value > @highest_wf_count
        @highest_wf_count = value
      end
    end
  end

  def highest_wf_count= (number)
    @highest_wf_count = number
  end

end


class Solution
  attr_reader :analyzers, :highest_count_across_lines, :highest_count_words_across_lines # Implement the following read-only attributes in the Solution class.

  def initialize() 
    @analyzers = []
    highest_count_across_lines = nil
    highest_count_words_across_lines = []
  end

  def analyze_file()
    File.foreach('test.txt').with_index(1) do |content, line|
      line_analyzer = LineAnalyzer.new(content, line)
      @analyzers << line_analyzer
    end
  end

  def calculate_line_with_highest_frequency()

     @highest_count_across_lines = analyzers.map(&:highest_wf_count).max
     @highest_count_words_across_lines = analyzers.select { |k,v| v = @highest_count_across_lines }
  end


  def print_highest_word_frequency_across_lines() 
    "The following words have the highest frequency per line: \n  #{highest_count_words_across_lines} (appears in line #{line_num} \n"  
  end
end

This is the error message I get:

Failures:

  1) Solution#calculate_line_with_highest_frequency calculates highest count words across lines to be will, it, really
     Failure/Error: expect(words_found).to match_array ["will", "it", "really"]

       expected collection contained:  ["it", "really", "will"]
       actual collection contained:    [{"a"=>1, "cool"=>1, "experiment"=>1, "is"=>1, "really"=>4, "this"=>1}, {"cute"=>1, "experiment"=>1, "little"=>1}, {"do"=>1, "it"=>4, "maybe"=>1, "think"=>1, "will"=>4, "work"=>2, "you"=>1}]
       the missing elements were:      ["it", "really", "will"]
       the extra elements were:        [{"a"=>1, "cool"=>1, "experiment"=>1, "is"=>1, "really"=>4, "this"=>1}, {"cute"=>1, "experiment"=>1, "little"=>1}, {"do"=>1, "it"=>4, "maybe"=>1, "think"=>1, "will"=>4, "work"=>2, "you"=>1}]
     # ./spec/solution_spec.rb:39:in `block (3 levels) in <top (required)>'

Finished in 0.26418 seconds (files took 0.38 seconds to load)
19 examples, 1 failure

Failed examples:

rspec ./spec/solution_spec.rb:31 # Solution#calculate_line_with_highest_frequency calculates highest count words across lines to be will, it, really

I've tried iterating through the hashes within an array but kept getting an error message. I am trying to find the keys where the values (counts) are equal to the highest count (4). So the final answer should be ["it","really","will"]. Any suggestions?

Password doesn't get updated for user in rails after reseting

I previously had a page as settings to update the user details in rails. On that time the password gets updated without any issue. But now I used a password reset option for the users who forgot their password. They will receive a mail and then they reset the password. After adding this feature both the updating inside the account and via mail does not happen.

password_reset controller:

def update

  @user = User.find_by_password_reset_token!(params[:id])
  if @user.password_reset_sent_at < 2.hour.ago
    flash[:notice] = 'Password reset has expired'

    redirect_to new_password_reset_path

  elsif @user.update_attributes(params[:user])// this condition fails. I don't know why it fails.

    flash[:notice] = 'Password has been reset!'
    redirect_to new_session_path
  else
   redirect_to new_session_path
  end

user.rb

  validates :password, presence: true, length: { minimum: 6 } 
  validates :password_confirmation, presence: true 
  before_save { |user| user.email = email.downcase }
  before_save :create_remember_token


  private

    def create_remember_token
      self.remember_token = SecureRandom.urlsafe_base64
    end

    def generate_token(column)
      begin
        self[column] = SecureRandom.urlsafe_base64
      end while User.exists?(column => self[column])
    end

These filters I used in user controller

 before_filter :signed_in_user, only: [:edit, :update, :requestuser]
 before_filter :correct_user,   only: [:edit, :update]
 before_filter :admin_user,     only: :destroy

I am new to rails and learning. Need help. The same filter I used before password reset I dont know why it fails. It first worked for few days now it fails.

Can somebody please please help me on Spiltting the package name in Ruby

Can somebody please please help me on splitting the below name in Ruby

package= AB-JACK_ABCD_gt_dkd_3-2-2-1-3.2.2.1-GIT.x86_32.exe

fullname= package.spilt
version= package.spilt
release= package.spilt

The following output need to be printed   
puts fullname >> ABCD_gt_dkd_3-2-2-1  
puts version >> 3.2.2.1  
puts release >> GIT  

Thanks in advance

samedi 14 septembre 2019

Masonry-Rails gutters break layout

I set up masonry rails on my website and when I click the logo to go to root path, the gutters disappear as if they were never there. Also when adding more the 4 posts for a second row it also glitches.

Image of the posts overlapping

Image no longer overlapping after hitting the link to go to root path

vendredi 13 septembre 2019

ActiveStorage issues not uploading or not loading

So im trying to add the ability for users (devise) to upload images to a listing.

First off: I have a listings controller and the listings params I have it defined

def listing_params
  params.require(:listing).permit(:title, :description, images: [])
end

Next: In the listing model I have:

class Listing < ApplicationRecord
  belongs_to :user
  has_many_attached :images
end

And finally, I have the form and the index set up with

= simple_form_for @listing do |f|
  = f.input :title
  = f.file_field :images, multiple: true
  = f.text_area :description
  = f.button :submit

.listings.has-gutters
  - @listings.each do |listing|
    .box
      - @listings.images.each do |image|
        = image_tag(@listings.images[image])
      .listing-info
        %h3= link_to listing.title, listing_path(listing)
        %p= listing.description
        %p= listing.user.firstname

With all this, I would assume it would work but when uploading the images it gives me the error:

NoMethodError in Listings#index
Showing /Users/timbogdanov/Desktop/vend/app/views/listings/index.html.haml where line #5 raised:

undefined method `images' for #<Listing::ActiveRecord_Relation:0x00007f8ef1208578>
Extracted source (around line #5):

  - @listings.each do |listing|
    .box
      - @listings.images.each do |image|
        = image_tag(@listings.images[image])
      .listing-info
        %h3= link_to listing.title, listing_path(listing)

programmatically clear cache: Rails

I had setup a Rails form. Later I added a jquery-ui autocomplete widget:

View file:

<%= f.text_field :doc_owner, data: {autocomplete_source: User.order(:user_name).where("full_name <> ''").pluck(:full_name)} %>

js coffee file:

$('#doc_queue_doc_owner').autocomplete
  source: $('#doc_queue_doc_owner').data('autocomplete-source')

The users who have been to this form before DO NOT see this feature until they clear their browser cache. Can I clear cache through model?

When does Passenger look for config.ru file?

I have an up and running Rails 3.2 application with Nginx and Phusion Passenger 5.0.29. Everything works, except that a request randomly got an error 500 in response.

I looked at the logs and found in the nginx error log:

[alert] 28998#0: *187443 Cannot stat '[...]/config.ru': Permission denied (errno=13);
This error means that the Nginx worker process [...] does not have permission
to access this file. 

Oddly, similar requests (same client & same URL) processed before and after the error did not trigger this error.

I looked at the load on the server as well, and couldn't see any unusual activity (memory, CPU and disk not particularly busy).

So maybe changing permissions of the config.ru file (& folders above) might fix this issue, but more importantly I'd like to understand how it happens, to be sure I'm not missing something important.

So basically I'd like to know :

  • when does Passenger looks at config.ru?
  • why is it written as an "alert" but actually returned a 500
  • why is the error not systematic, ie why similar requests don't make Passenger look at config.ru as well?

How can i read from a document.txt lines with emoji and show them on terminal when i run the ruby code?

I want to read a document file .txt in Ruby but the following lines of this document contain emojis and when i run the program it shows me different symbols and not the actual emoji. I have already tried different methods. How can i do this , should i install any gem ??

file='document.txt'

This document contains the following line with emojis

This is a test line 🔥🔥🔥

  File.readlines(file).each do |line|

      puts line

  end

jeudi 12 septembre 2019

sum method alternatives for active records

I am in a legacy Ruby on Rails project. Rails v2.3.9.

I have a model class product, in database there is products table.

class Product < ActiveRecord::Base

  ...
end

There is price attribute which is a integer type.

I got all products (ActiveRecords) at some point. I need to calculate the total price of all products I got. I know I can do:

total_price = all_products.sum(&:price)

It works.

But it also triggers a database query SELECT sum(...). Is there an alternative way to calculate the summation of price of all products without triggering any database query? I know I can use for loop, but I wonder any other ways?

Ruby Watir : How can i switch between tabs on a Chrome window, focus and work on both of them, or switch between to window browser of Chrome?

I want to make a automation script that switches between 2 tabs of Chrome and focus on them or i have tried to open 2 different Chrome browser windows but i can focus on second one and then focus on the first one.

require 'watir'

browser = Watir::Browser.new :chrome
browser.goto "https://google.com/"
sleep(5)

I can open a new tab using execute_script but i can not focus and then switch again to the first tab

browser.execute_script('window.open("www.facebook.com")')

lundi 9 septembre 2019

Why Session does not reset after changing auth salt in devise in test enviornment?

I want to write rspec for a feature in which when I change the authenticable_salt it resets the devise session. Here is a reference. It is working fine in the development enviornment but when I am trying to write a controller test it does not change the session.

I have overridden the Devise#authenticable_salt in app/model/user.rb

  def authenticatable_salt
   "#{super}#{email}"
  end

My rspec code looks like

it 'logs out user when email is changed' do
  sign_in_with_host(@user)
  expect(controller.current_user).to eq(@user)
  get :index
  @user.update_attribute(:email, 'somethingelse@mail.com')
  get :index
  expect(controller.current_user).to be_nil
end

In the above code you can see I have changed the salt by updating the email but the session before and updating the attribute is same in test env but when I check in the development server as soon as I update the email it resets the session.

NOTE: Please note that I am using rails3.2 version and devise 3.5.10.

vendredi 6 septembre 2019

Use Rails 4 Syntax For Associations in Rails 3.2

Is there any way I can support the Rails 4 syntax for defining associations in Rails 3.2?

I currently have the following Rails 4 syntax:

has_many :clients, -> { where("client_type = 'temp'").order("name DESC") }

I want my Rails 3.2 app to support that syntax. In essence, it's as if I had written the following in Rails 3.2:

has_many :clients, conditions: "client_type = 'temp'", order: "name DESC"

Is there a library/gem that enables this support? Any ideas on how to accomplish this?

Add class Ruby on rails select tag

How to add myClass. Help pleace

``<%= select_hour(@work_hour, field_name: 'hour', start_hour: @start, end_hour:@end, :class => 'form-control' ) %>

`` ERRORS

mercredi 4 septembre 2019

Pundit with second devise model

I manage the authorization of users in my app with the pundit gem. Everything works fine for the user. Now I created a second devise model: Employers. I want to show a specific page to both logged in user as well as logged in employers. How do I do that?

Here is my policy for the model:

class CurriculumPolicy < ApplicationPolicy
  class Scope < Scope
    def resolve
      scope.all
    end
  end

  def create?
    return true
  end

  def show?
    record.user == user || user.admin
  end

  def update?
    record.user == user || user.admin
  end

  def destroy?
    record.user == user || user.admin
  end
end

And here is my controller for the index page which I want to make accessible:

class CurriculumsController < ApplicationController
    skip_before_action :authenticate_user!, only: [:new, :create, :index]
    before_action :set_curriculum, only: [:show, :edit, :update, :destroy]

  def index
    # @curriculums = policy_scope(Curriculum).order(created_at: :desc)
    if params[:query]
  @curriculums = policy_scope(Curriculum).joins(:user)
               .where('users.job_category ILIKE ?', "%#{params[:query]}%")
               .where(
                 'job_category ILIKE :query', query: "%#{params[:query]}%"
                )
    else
    @curriculums = policy_scope(Curriculum).order(created_at: :desc)
    end
  end

  private

   def set_curriculum
      @curriculum = Curriculum.find(params[:id])
    end

  def curriculum_params
      params.require(:curriculum).permit(:doc)
  end

end

mardi 3 septembre 2019

How to convert date with time along with UTC (18/Sep/2012:09:57:41 -0500) to timestamp in Ruby?

I need to convert 18/Sep/2012:09:57:41 -0500 to timestamp in ruby.

What is 'in?' in ruby?

I am stuck here in code when I use in? method in ruby as follow:

'ruby programming'.in?('ruby')
=> false 

'ruby programming'.in?('ruby programming')
=> true

['ruby'].in?('ruby')
=> TypeError: no implicit conversion of Array into String

This method is like a include?, but behaving differently for different objets.

what actually doing in? method?

lundi 2 septembre 2019

Throwing Exeption control characters are not allowed at line 1 column 1 while using Psych.load_stream, YAML.load in ruby

Psych.load, Psych.parse, Psych.parse_stream

Psych.load_stream(input) do |doc|

Ruby-on-Rails: route for path with arbitrary number of components?

In my ror application, I want to define a route that will dispatch any length path to a given handler.

I want any URL which begins with http://example.com/xyz/... to go to the same handler, with the full path being passed in as an argument.

In other words, any and all of the following URL's should go to the same handler for the xyz route ...

  • http://example.com/xyz
  • http://example.com/xyz/foo
  • http://example.com/xyz/foo/bar
  • http://example.com/xyz/quack/bark/oink
  • http://example.com/xyz/hip/po/pot/a/mus
  • http://example.com/xyz/[any arbitrary path with any number of components]

... and within the handler, I need to be able to retrieve the entire path that was submitted.

I thought that I should put something like this into config/routes.rb ...

get "xyz/[what goes here?]", to: "xyz#handler"

... but I could not figure out any way to make this work in ror. Am I out of luck?

How to remove scrollbar from tables

I am making a table that gets data from datatables in ruby on rails. I want the rows to autofit if the browser is smaller, instead of making a scrollbar on the width. The scrollbar should never come no matter what.

I tried some css like table-layout: fixed

dimanche 1 septembre 2019

how to change the text in the button after the button is clicked in rails

I initially have a button which has text "follow" after clicking it I need it to change it to "requested" or any other text. How it can be done.