Peter vande Put

Joined

1,120 Experience
0 Lessons Completed
1 Question Solved

Activity

Posted in Root route bypassing before_action

we have a posts_controller which takes a slug to render the correct page.
posts_controller inherits from application_controller which has a couple of before_actions

routes.rb has the following root

    root  'posts#show_post'

The before_actions are not called when going to localhost:3000 which renders the correct post.

also in the log i don't see the show_post action being called.
What am I missing here?

In our application we generate several reports. Instead of downloading them as Excel or CSV want to render them similar to Excel/Google sheet
anyone any ideas what the best approach is?

In our system we are sending webhook to an endpoint with serialized JSON for the object JobApplication.
The JobApplication has a resume attached using ActiveStorage. ( has_one_attached :resume)
How can I return a public URL to the resume in my JSON

class JobApplicationSerializer
  def self.exploded_json(object)
    json =object.to_json(:except => [:user_id,:created_at, :updated_at],
                         :include => [
                           :state => {:only => [:id, :name,:code]},
                           :country => {:only => [:id, :name,:code]}
                         ]
    )
    return json
  end

end

Posted in splitting asset pipeline for front and backend

app has a consumer facing part and large backend/CMS part.
our assets (JS and SCSS) are precompiled into a very large file
in layouts we have a different layout for front- and backend

Is it possible to split assets:precompile into a front end and a backend part?

using asset_sync gem and fog

Posted in How can I force cloudfront assets to use http2?

in our app we have an image library which stores images in S3 linked to cloudfront.
cloudfront configured for http2
server is puma + nginx
problem is performance seems like all assets served from cloudfront/xxxxxx are using http1.1 instead of http2

how can this be solved?

Posted in How to have one application for multiple URL's

We have a requirement where are rails application should be available on multiple domains like abc.com and xyz.com
based on domain it will only show a different logo all the rest is identical.
What's the best approach for this ? all tips are welcome

Posted in How can I display production s3 images in staging?

What I do is copy the production bucket to the staging bucket from time to time.
Have a simple Ruby script to do this.

Your model is wrong it's better to have a model named partner for example which has a partner type. Now you can seed it with partner types like Vendor, Customer, Supplier Both, whatever you want

class CreatePartnerTypes < ActiveRecord::Migration[5.2]
  def change
    create_table :partner_types do |t|
      t.string :name
      t.timestamps
    end
    add_index :partner_types, :name,  unique: true
  end
end

class CreatePartners < ActiveRecord::Migration[5.2]
  def change
    create_table :partners do |t|
      t.references :company
      t.references :partner_type
      t.string :name
      t.string :address
      t.string :postal_code
      t.string :city
      t.references :state
      t.timestamps
    end
  end
end


Posted in Is there an episode on Post Production Updates?

  1. Make sure to work from different branches in git (e.g. master branch is on your production server and develop is on your staging and local)
  2. Do not make changes to your to exisiting migrations, if you need to change/create models create a migration for it.
  3. In case you add a field to a modal and you are using it in a control flow make sure to set a default value
  4. New Controllers/Views can be added like normal
  5. After local testing deploy to your staging server * git pull * rails db:migrate * start your server
  6. If all is verified do the same on production from your master branch, restart your services

My system is using a post model with friendly_id so the calls are /name_of_the_post and this works great.
The initial home page is also a post so in routes.rb I have

    root 'home#index'
        get ':slug', to: 'posts#show_post', as: 'show_post'

    ```
    My HomeController has the following index action
    ```
        def index
        redirect_to '/home'
    end
    ```
    The PostsController will pick up home slug and show the post, however my URL is now localhost:3000/home and I want it to be 
    localhost:3000/

    How can I achieve this stripping the home slug (only for home)
logo Created with Sketch.

Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

© 2020 GoRails, LLC. All rights reserved.