title: Rails | Too many redirects
body: <p>I have routes such as;</p>
  
  <pre><code>scope to: 'search#show' do
    get '/search/:country_id/:rental_type_id/:group_id', as: 'search_country'
    get '/search/:country_id/:city_id/:rental_type_id/:group_id', as: 'search_city'
  end
  </code></pre>
  
  <p>My problem is, when there is city as well, I should redirect to <code>search_city_path</code> but both routes are handled at <code>search#show</code> action.</p>
  
  <p>When I check if there is <code>city_id</code> and redirect to show action again, it start infinite redirection. How can I prevent this?</p>
  
  <p>Here is my show action;</p>
  
  <pre><code>  def show
  
  
      @rental_type = RentalType.friendly.find(params[:rental_type_id])    
      @group = Group.friendly.find(params[:group_id])
  
      if !params[:boat_city_id].blank?
  
        @country = Country.friendly.find(params[:country_id])  
        @city = City.friendly.find(params[:city_id])
  
          redirect_to search_city_path(country_id: @country, city_id: @city, rental_type_id: @rental_type, group_id: @group, q: params[:q])
        else
          @country = Country.friendly.find(params[:country_id])  
      end  
  ....
  </code></pre>
  
  <p><strong>EDIT</strong></p>
  
  <p>Show action;</p>
  
  <pre><code>def show
  
  
      @rental_type = RentalType.friendly.find(params[:rental_type_id])    
      @boat_group = BoatGroup.friendly.find(params[:boat_group_id])
  
  
  
  
      if !params[:new_boat_country_id].nil? &amp;&amp; params[:new_boat_country_id] != params[:boat_country_id] 
  
        @country = BoatCountry.friendly.find(params[:new_boat_country_id])
        redirect_to search_country_path(boat_country_id: @country, rental_type_id: @rental_type, boat_group_id: @boat_group, q: params[:q])
  
      elsif !params[:boat_city_id].blank?
  
        @country = BoatCountry.friendly.find(params[:boat_country_id])  
        @city = BoatCity.friendly.find(params[:boat_city_id])
  
          render 'search_city'
        else
          @country = BoatCountry.friendly.find(params[:boat_country_id])  
      end  
  
  
  
      if BoatGroup.friendly.find(params[:boat_group_id]).name == 'All' 
  
        if params[:boat_city_id].blank?
          b = @country.boats.where("(stat = ? AND boat_category = ?)", "Approved", "list" )
        else
          @city = BoatCity.friendly.find(params[:boat_city_id])
          b = @city.boats.where("(stat = ? AND boat_category = ?)", "Approved", "list" )
        end
  
      else
        b = @boat_group.boats.where("(stat = ? AND boat_category = ?)", "Approved", "list" )
      end
  
  
  
        @q = b.ransack(params[:q])
        @boats = @q.result(distinct: true).paginate(:page =&gt; params[:page], :per_page =&gt; 15)
  
  
    end
  </code></pre>