DollarChills
DollarChills

Reputation: 1096

No route matches on dynamic page

I'm trying to create a dynamic page based on the trial_id from the Trial controller. I have it showing the right url, but get a No route matches [GET] error. I'm using rails 4.2.0 and this worked previously on 3.2, but i think I'm missing something.

View

<% @regions.each do |region, list| %>
  <%= region %>
    <% list.sort{ |a,b| a.site.site_name <=> b.site.site_name }.each do |list| %>
      <% paths = trials_show_path(trial_id: list.trial_id)
         path = paths.gsub("?trial_id=", "/")
      %>

<%= link_to list.site.site_name, path %>

<% end %>
<% end %>

Show Controller

@results = Trial.trial_id(params[:trial_id])

Trial Model

scope :trial_id, -> (trial_id) { where(trial_id: trial_id) }

Routes

  get 'trials', :to => 'trials#index'
  get 'trials/show'

Upvotes: 0

Views: 48

Answers (1)

Uday kumar das
Uday kumar das

Reputation: 1613

Use this custom route in your routes.rb file.

get 'trials/index/:trail_id' => 'trials#index',:as=>'trails'

get 'trials/show'

And then use 'trails_path' in your views.

Upvotes: 1

Related Questions