I have an index for a model "arbete" and if an :id is supplied it filters the index and shows only the index for the vehicle with the id.
if I create a link_to in the view that shows the whole index again it still generates the index link and the id again even though I havenĀ“t supplied an action or an id.
link_to("show all", :controller => 'arbete')
generates:
<a href="/arbete/index/22">show all</a>
The only solution I have found is to specify :id => ' ' and then I get the link:<a href="/arbete/index">
why is it behaving like this?
Update
arbete_controller.rb
def index
@arbetecl = Arbete.order("id ASC").where(:oppen => false)
if params[:id].present?
@vehicle = Vehicle.find(params[:id])
@arbeteop = @vehicle.arbetes.all
else
@arbeteop = Arbete.order("id ASC").where(:oppen => true)
end
link in view
<li><%= link_to "Testarbete", :controller => 'arbete' %></li>
generates if the id params is sent.
<li><a href="/arbete/index/67">Testarbete</a></li>
routes.rb
match ':controller(/:action(/:id))', :via => [:get, :post]
Im thinking its a desired behaviour but I cant find why and it only happens on this model and controller but its also the only one that gets params to its index action.