Note that there are some explanatory texts on larger screens.

plurals
  1. PORails GET not translating slugged id with extra parameters
    primarykey
    data
    text
    <p>I have a model which is linking to the show method:</p> <pre><code>&lt;%= link_to "View Others", :controller =&gt; "browse", :action =&gt; "show", :id =&gt; @id, :d =&gt; "25" %&gt; </code></pre> <p>Clicking the link gives: <a href="http://localhost:3000/browse/santa-cruz?d=25" rel="nofollow">http://localhost:3000/browse/santa-cruz?d=25</a></p> <p>Rails gives the error though:</p> <pre><code>No route matches {:controller=&gt;"browse", :action=&gt;"show", :id=&gt;nil, :d=&gt;"25"} </code></pre> <p>If I take the extra parameter off everything works. </p> <pre><code>&lt;%= link_to "View Others", :controller =&gt; "browse", :action =&gt; "show", :id =&gt; @id %&gt; </code></pre> <p>Goes to <a href="http://localhost:3000/browse/santa-cruz" rel="nofollow">http://localhost:3000/browse/santa-cruz</a> This page loads and I am getting the correct params[:id] </p> <p>Any ideas?</p> <p>Pasted bellow is the show for my controller</p> <pre><code>def show if params[:d].nil? then # Show list of addresses in city. addresses = Address.where(:slug =&gt; params[:id]) profile = [] addresses.each do |ad| profile &lt;&lt; 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 =&gt; 'pages', :action =&gt; 'notlaunched', :zip =&gt; params[:id] end else # :d exists # show all within :d miles. addresses = Address.where(:slug =&gt; params[:id]) nearby = Address.near("#{addresses.first.fulladdress}", params[:d], :order =&gt; :distance) profiles = nearby.map{ |ad| ad.profile }.uniq end end </code></pre> <p>Here's the Index:</p> <pre><code>def index cities = [] states = [] Address.find_each do |ad| cities &lt;&lt; { :city =&gt; ad.city, :slug =&gt; ad.slug } # slug becomes the :id of show states &lt;&lt; ad.state end @cities = cities.uniq @states = states.uniq @title = "Browse Cities" end </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload