Search code examples
apacheruby-on-rails-4passengerubuntu-14.04

Rails App on Ubuntu running Apache and Passenger throws 404 with params


I am trying to set up a server to host my rails apps. I have one I am testing and it is giving me a 404 error when I call a controller action while passing params in the URL. I have this app deployed on Heroku and it runs perfectly. Any action that is called without params work perfectly on the new server. It is only the action that passes the params that is giving me the 404.

Also I ran it locally with Webrick on the server and it works fine. It only has this issue when running on passenger.

Any ideas what might cause this or where I should start to find the issue?

This is the request being sent Request GET /groups/2/set_and_redirect/%2Fgroups%2F2%2Fgroups_lists HTTP/1.1

This is the body of the 404 response The requested URL /groups/2/set_and_redirect//groups/2/groups_lists was not found on this server.

Edit

This is the partial that is causing the issue. Specificaly the link_to group.name. The edit and delete both work fine and the set and redirect works fine on Heroku and Webrick.

<% @groups.each do |group| %>
    <h4><div>
      <%= link_to group.name, groups_set_and_redirect_path(:id => group.id, :path => group_list_path(id: group.id) ), remote: true %>&nbsp;&nbsp;
      <%= link_to ('<i class="glyphicon glyphicon-edit"></i>').html_safe, edit_group_path(group),'data-toggle' => 'modal', 'data-target' => "#group-modal#{group.id}", remote: true %>&nbsp;&nbsp;

      <%= link_to ('<i class="glyphicon glyphicon-trash text-danger"></i>').html_safe, group, method: :delete, data: { confirm: 'Are you sure?' }, remote: true %>
    </div></h4>
<%end%>
<div> <%= link_to ('<i class="glyphicon glyphicon-plus text-success"></i>').html_safe, "#group-modal", 'data-toggle' => 'modal', class: 'btn btn-lg' %> </div>

I changed my route from

get 'groups/:id/set_and_redirect/:path' => 'groups#set_and_redirect', :as => :groups_set_and_redirect

to

get 'groups/:id/set_and_redirect' => 'groups#set_and_redirect', :as => :groups_set_and_redirect

and now it works


Solution

  • Adjust your routes.rb so that a double slash doesn't occur (perhaps by using a named parameter for path).