2

I’m currently building a Rails app that has some React components mixed in using rails/webpacker. They are being rendered out in views like this:

<%= react_component("CampaignTable", campaigns: @plan.campaigns.today, props: {tableTitle: "Upcoming"}) %>

The structure is that I have a Plan model which has_many :campaigns. On that Campaign model I have a class method to get the ones from the current day:

def self.today
  where('"end" >= ?', Time.zone.now.beginning_of_day)
end 

What I’d like to do is to be able to pass the campaign_paths into my React components as props, so that I can render out regular links to the non-React parts of the app.

Ideally my props should look like this:

{
  id: 18,
  budget_cents: 50000,
  created_at: "2018-03-29T00:49:58.000Z",
  // etc…
  campaign_path: "/campaigns/18"
}

What is the best way to approach this?

gosseti
  • 965
  • 16
  • 40

0 Answers0