У меня есть модель, которая ссылается на метод show:
<%= link_to "View Others", :controller => "browse",
:action => "show", :id => @id, :d => "25" %>
Нажав на ссылку, вы получите:
http://localhost:3000/browse/santa-cruz?d=25
Rails выдает ошибку:
No route matches {:controller=>"browse", :action=>"show", :id=>nil, :d=>"25"}
Если я уберу дополнительный параметр, все будет работать.
<%= link_to "View Others", :controller => "browse",
:action => "show", :id => @id %>
Переходит к http://localhost:3000/browse/santa-cruz
Эта страница загружается, и я получаю правильные параметры [: id]
Есть идеи?
Вставленный ниже показ для моего контроллера
def show
if params[:d].nil? then
# Show list of addresses in city.
addresses = Address.where(:slug => params[:id])
profile = []
addresses.each do |ad|
profile << ad.profile
end
unless profile.blank?
@profile = Kaminari.paginate_array(profile).page(params[:page]).per(5)
@title = "Profiles Near " + addresses.first.city
@id = params[:id]
else
redirect_to :controller => 'pages', :action => 'notlaunched', :zip => params[:id]
end
else # :d exists
# show all within :d miles.
addresses = Address.where(:slug => params[:id])
nearby = Address.near("#{addresses.first.fulladdress}", params[:d], :order => :distance)
profiles = nearby.map{ |ad| ad.profile }.uniq
end
end
Вот индекс:
def index
cities = []
states = []
Address.find_each do |ad|
cities << { :city => ad.city, :slug => ad.slug } # slug becomes the :id of show
states << ad.state
end
@cities = cities.uniq
@states = states.uniq
@title = "Browse Cities"
end