ActiveRecord find ignores extra characters after numeric id. ?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

ActiveRecord find ignores extra characters after numeric id. ?

fugee ohu
Doesn't work for me in rails 6

  Parameters: {"id"=>"18-test-title"}
 ActionController::ActionControllerError (Cannot redirect to nil!):

Ne

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/64e66550-c393-43cd-8156-29c43139899a%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: ActiveRecord find ignores extra characters after numeric id. ?

Ariel Juodziukynas

Person.find("31-sarah") # returns the object for ID = 31
In your case, if you are using find, it should search for record with id = 18

El mié., 15 ene. 2020 a las 16:18, fugee ohu (<[hidden email]>) escribió:
Doesn't work for me in rails 6

  Parameters: {"id"=>"18-test-title"}
 ActionController::ActionControllerError (Cannot redirect to nil!):

Ne

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/64e66550-c393-43cd-8156-29c43139899a%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAPS3bcA8PH7D9tzqAWTWLF0gK8vYUrO4G5xjJa3rgM41rxP-cw%40mail.gmail.com.
Reply | Threaded
Open this post in threaded view
|

Re: ActiveRecord find ignores extra characters after numeric id. ?

fugee ohu


On Wednesday, January 15, 2020 at 3:07:00 PM UTC-5, Ariel Juodziukynas wrote:
From the docs: <a href="https://apidock.com/rails/v6.0.0/ActiveRecord/FinderMethods/find" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fapidock.com%2Frails%2Fv6.0.0%2FActiveRecord%2FFinderMethods%2Ffind\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHk5NLLhYgd7d5nLYxRp4OAkVps7A&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fapidock.com%2Frails%2Fv6.0.0%2FActiveRecord%2FFinderMethods%2Ffind\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHk5NLLhYgd7d5nLYxRp4OAkVps7A&#39;;return true;">https://apidock.com/rails/v6.0.0/ActiveRecord/FinderMethods/find

<a href="https://apidock.com/rails/Person" style="color:rgb(35,63,191)" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fapidock.com%2Frails%2FPerson\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNF4msDio5qDj8lVMu7J8TATciuEYw&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fapidock.com%2Frails%2FPerson\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNF4msDio5qDj8lVMu7J8TATciuEYw&#39;;return true;">Person.<a href="https://apidock.com/rails/ActiveRecord/FinderMethods/find" style="color:rgb(35,63,191)" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fapidock.com%2Frails%2FActiveRecord%2FFinderMethods%2Ffind\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNE4B-AvP-YwcXqN38gJXSTwhos52w&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fapidock.com%2Frails%2FActiveRecord%2FFinderMethods%2Ffind\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNE4B-AvP-YwcXqN38gJXSTwhos52w&#39;;return true;">find("31-sarah") # returns the object for ID = 31
In your case, if you are using find, it should search for record with id = 18

El mié., 15 ene. 2020 a las 16:18, fugee ohu (<<a href="javascript:" target="_blank" gdf-obfuscated-mailto="zoF3Os2PDAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">fuge...@...>) escribió:
Doesn't work for me in rails 6

  Parameters: {"id"=>"18-test-title"}
 ActionController::ActionControllerError (Cannot redirect to nil!):

Ne

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="zoF3Os2PDAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">rubyonra...@googlegroups.com.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/rubyonrails-talk/64e66550-c393-43cd-8156-29c43139899a%40googlegroups.com?utm_medium=email&amp;utm_source=footer" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/rubyonrails-talk/64e66550-c393-43cd-8156-29c43139899a%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/rubyonrails-talk/64e66550-c393-43cd-8156-29c43139899a%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/rubyonrails-talk/64e66550-c393-43cd-8156-29c43139899a%40googlegroups.com.

I've over-riding ActiveRecord to_param in my model

  def to_param
   "#{id}-#{title.parameterize}"
  end

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/1ba590e7-4c1c-4fcd-9ed8-0f2ed65b0350%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: ActiveRecord find ignores extra characters after numeric id. ?

Ariel Juodziukynas
find method doesn't care about the to_param method, it just takes the parameter you use, I guess it calls "to_i" and uses that integer to query the id column

Why don't you show your code, the stacktrace, the logs or anything? I suggest you read something like stackoverflow's guidelines on how to ask, you posts are usually really hard to understand and a lot of information is missing

El mié., 15 ene. 2020 a las 18:01, fugee ohu (<[hidden email]>) escribió:


On Wednesday, January 15, 2020 at 3:07:00 PM UTC-5, Ariel Juodziukynas wrote:

Person.find("31-sarah") # returns the object for ID = 31
In your case, if you are using find, it should search for record with id = 18

El mié., 15 ene. 2020 a las 16:18, fugee ohu (<[hidden email]>) escribió:
Doesn't work for me in rails 6

  Parameters: {"id"=>"18-test-title"}
 ActionController::ActionControllerError (Cannot redirect to nil!):

Ne

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/64e66550-c393-43cd-8156-29c43139899a%40googlegroups.com.

I've over-riding ActiveRecord to_param in my model

  def to_param
   "#{id}-#{title.parameterize}"
  end

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/1ba590e7-4c1c-4fcd-9ed8-0f2ed65b0350%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAPS3bcDQU%2BQLcCOftreFJb0UdUFYUYPAFM%3DCm1xCO2qomsQ6Ag%40mail.gmail.com.
Reply | Threaded
Open this post in threaded view
|

Re: ActiveRecord find ignores extra characters after numeric id. ?

fugee ohu


On Wednesday, January 15, 2020 at 8:26:45 PM UTC-5, Ariel Juodziukynas wrote:
find method doesn't care about the to_param method, it just takes the parameter you use, I guess it calls "to_i" and uses that integer to query the id column

Why don't you show your code, the stacktrace, the logs or anything? I suggest you read something like stackoverflow's guidelines on how to ask, you posts are usually really hard to understand and a lot of information is missing

El mié., 15 ene. 2020 a las 18:01, fugee ohu (<<a href="javascript:" target="_blank" gdf-obfuscated-mailto="9DO1-z-hDAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">fuge...@...>) escribió:


On Wednesday, January 15, 2020 at 3:07:00 PM UTC-5, Ariel Juodziukynas wrote:
From the docs: <a href="https://apidock.com/rails/v6.0.0/ActiveRecord/FinderMethods/find" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fapidock.com%2Frails%2Fv6.0.0%2FActiveRecord%2FFinderMethods%2Ffind\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHk5NLLhYgd7d5nLYxRp4OAkVps7A&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fapidock.com%2Frails%2Fv6.0.0%2FActiveRecord%2FFinderMethods%2Ffind\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHk5NLLhYgd7d5nLYxRp4OAkVps7A&#39;;return true;">https://apidock.com/rails/v6.0.0/ActiveRecord/FinderMethods/find

<a href="https://apidock.com/rails/Person" style="color:rgb(35,63,191)" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fapidock.com%2Frails%2FPerson\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNF4msDio5qDj8lVMu7J8TATciuEYw&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fapidock.com%2Frails%2FPerson\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNF4msDio5qDj8lVMu7J8TATciuEYw&#39;;return true;">Person.<a href="https://apidock.com/rails/ActiveRecord/FinderMethods/find" style="color:rgb(35,63,191)" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fapidock.com%2Frails%2FActiveRecord%2FFinderMethods%2Ffind\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNE4B-AvP-YwcXqN38gJXSTwhos52w&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fapidock.com%2Frails%2FActiveRecord%2FFinderMethods%2Ffind\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNE4B-AvP-YwcXqN38gJXSTwhos52w&#39;;return true;">find("31-sarah") # returns the object for ID = 31
In your case, if you are using find, it should search for record with id = 18

El mié., 15 ene. 2020 a las 16:18, fugee ohu (<[hidden email]>) escribió:
Doesn't work for me in rails 6

  Parameters: {"id"=>"18-test-title"}
 ActionController::ActionControllerError (Cannot redirect to nil!):

Ne

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/rubyonrails-talk/64e66550-c393-43cd-8156-29c43139899a%40googlegroups.com?utm_medium=email&amp;utm_source=footer" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/rubyonrails-talk/64e66550-c393-43cd-8156-29c43139899a%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/rubyonrails-talk/64e66550-c393-43cd-8156-29c43139899a%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/rubyonrails-talk/64e66550-c393-43cd-8156-29c43139899a%40googlegroups.com.

I've over-riding ActiveRecord to_param in my model

  def to_param
   "#{id}-#{title.parameterize}"
  end

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="9DO1-z-hDAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">rubyonra...@googlegroups.com.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/rubyonrails-talk/1ba590e7-4c1c-4fcd-9ed8-0f2ed65b0350%40googlegroups.com?utm_medium=email&amp;utm_source=footer" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/rubyonrails-talk/1ba590e7-4c1c-4fcd-9ed8-0f2ed65b0350%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/rubyonrails-talk/1ba590e7-4c1c-4fcd-9ed8-0f2ed65b0350%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/rubyonrails-talk/1ba590e7-4c1c-4fcd-9ed8-0f2ed65b0350%40googlegroups.com.

I was trying to implement this guide:
https://medium.com/badass-engineer/seo-friendly-urls-with-rails-49cfcd2fb190

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/1aa0ed3a-a906-4965-8ff1-c8fde1e909da%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: ActiveRecord find ignores extra characters after numeric id. ?

Ariel Juodziukynas
I insist, show your code, show the complete error stacktrace, show the log. I can imagine what you are trying to do and from the (little) code you show it should work so something else is messing things up but you are showing barely any relevant code.

El mié., 15 ene. 2020 a las 22:37, fugee ohu (<[hidden email]>) escribió:


On Wednesday, January 15, 2020 at 8:26:45 PM UTC-5, Ariel Juodziukynas wrote:
find method doesn't care about the to_param method, it just takes the parameter you use, I guess it calls "to_i" and uses that integer to query the id column

Why don't you show your code, the stacktrace, the logs or anything? I suggest you read something like stackoverflow's guidelines on how to ask, you posts are usually really hard to understand and a lot of information is missing

El mié., 15 ene. 2020 a las 18:01, fugee ohu (<[hidden email]>) escribió:


On Wednesday, January 15, 2020 at 3:07:00 PM UTC-5, Ariel Juodziukynas wrote:

Person.find("31-sarah") # returns the object for ID = 31
In your case, if you are using find, it should search for record with id = 18

El mié., 15 ene. 2020 a las 16:18, fugee ohu (<[hidden email]>) escribió:
Doesn't work for me in rails 6

  Parameters: {"id"=>"18-test-title"}
 ActionController::ActionControllerError (Cannot redirect to nil!):

Ne

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/64e66550-c393-43cd-8156-29c43139899a%40googlegroups.com.

I've over-riding ActiveRecord to_param in my model

  def to_param
   "#{id}-#{title.parameterize}"
  end

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/1ba590e7-4c1c-4fcd-9ed8-0f2ed65b0350%40googlegroups.com.

I was trying to implement this guide:

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/1aa0ed3a-a906-4965-8ff1-c8fde1e909da%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAPS3bcAhMWv_1GduYuKyRe5D%3DexpX_ata7B-kL0fnTwFRc86Tg%40mail.gmail.com.
Reply | Threaded
Open this post in threaded view
|

Re: ActiveRecord find ignores extra characters after numeric id. ?

fugee ohu
The error's caused by the routine ensure_canonical_url If I comment it out it works

blog_post.rb:

  def to_param
   "#{id}-#{title.parameterize}"
  end

blog_posts_controller.rb:

    def set_blog_post
      @blog_post = BlogPost.find(params[:id])
    end

    def ensure_canonical_url
      redirect_to @blog_post if @blog_post.to_param != params[:id]
    end


On Wednesday, January 15, 2020 at 8:41:00 PM UTC-5, Ariel Juodziukynas wrote:
I insist, show your code, show the complete error stacktrace, show the log. I can imagine what you are trying to do and from the (little) code you show it should work so something else is messing things up but you are showing barely any relevant code.

El mié., 15 ene. 2020 a las 22:37, fugee ohu (<<a href="javascript:" target="_blank" gdf-obfuscated-mailto="WeppIQeiDAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">fuge...@...>) escribió:


On Wednesday, January 15, 2020 at 8:26:45 PM UTC-5, Ariel Juodziukynas wrote:
find method doesn't care about the to_param method, it just takes the parameter you use, I guess it calls "to_i" and uses that integer to query the id column

Why don't you show your code, the stacktrace, the logs or anything? I suggest you read something like stackoverflow's guidelines on how to ask, you posts are usually really hard to understand and a lot of information is missing

El mié., 15 ene. 2020 a las 18:01, fugee ohu (<[hidden email]>) escribió:


On Wednesday, January 15, 2020 at 3:07:00 PM UTC-5, Ariel Juodziukynas wrote:
From the docs: <a href="https://apidock.com/rails/v6.0.0/ActiveRecord/FinderMethods/find" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fapidock.com%2Frails%2Fv6.0.0%2FActiveRecord%2FFinderMethods%2Ffind\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHk5NLLhYgd7d5nLYxRp4OAkVps7A&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fapidock.com%2Frails%2Fv6.0.0%2FActiveRecord%2FFinderMethods%2Ffind\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHk5NLLhYgd7d5nLYxRp4OAkVps7A&#39;;return true;">https://apidock.com/rails/v6.0.0/ActiveRecord/FinderMethods/find

<a href="https://apidock.com/rails/Person" style="color:rgb(35,63,191)" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fapidock.com%2Frails%2FPerson\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNF4msDio5qDj8lVMu7J8TATciuEYw&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fapidock.com%2Frails%2FPerson\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNF4msDio5qDj8lVMu7J8TATciuEYw&#39;;return true;">Person.<a href="https://apidock.com/rails/ActiveRecord/FinderMethods/find" style="color:rgb(35,63,191)" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fapidock.com%2Frails%2FActiveRecord%2FFinderMethods%2Ffind\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNE4B-AvP-YwcXqN38gJXSTwhos52w&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fapidock.com%2Frails%2FActiveRecord%2FFinderMethods%2Ffind\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNE4B-AvP-YwcXqN38gJXSTwhos52w&#39;;return true;">find("31-sarah") # returns the object for ID = 31
In your case, if you are using find, it should search for record with id = 18

El mié., 15 ene. 2020 a las 16:18, fugee ohu (<[hidden email]>) escribió:
Doesn't work for me in rails 6

  Parameters: {"id"=>"18-test-title"}
 ActionController::ActionControllerError (Cannot redirect to nil!):

Ne

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/rubyonrails-talk/64e66550-c393-43cd-8156-29c43139899a%40googlegroups.com?utm_medium=email&amp;utm_source=footer" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/rubyonrails-talk/64e66550-c393-43cd-8156-29c43139899a%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/rubyonrails-talk/64e66550-c393-43cd-8156-29c43139899a%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/rubyonrails-talk/64e66550-c393-43cd-8156-29c43139899a%40googlegroups.com.

I've over-riding ActiveRecord to_param in my model

  def to_param
   "#{id}-#{title.parameterize}"
  end

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/rubyonrails-talk/1ba590e7-4c1c-4fcd-9ed8-0f2ed65b0350%40googlegroups.com?utm_medium=email&amp;utm_source=footer" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/rubyonrails-talk/1ba590e7-4c1c-4fcd-9ed8-0f2ed65b0350%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/rubyonrails-talk/1ba590e7-4c1c-4fcd-9ed8-0f2ed65b0350%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/rubyonrails-talk/1ba590e7-4c1c-4fcd-9ed8-0f2ed65b0350%40googlegroups.com.

I was trying to implement this guide:
<a href="https://medium.com/badass-engineer/seo-friendly-urls-with-rails-49cfcd2fb190" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fmedium.com%2Fbadass-engineer%2Fseo-friendly-urls-with-rails-49cfcd2fb190\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNH3Pquo_EhZuxCV7LvjXPoHnBeaRA&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fmedium.com%2Fbadass-engineer%2Fseo-friendly-urls-with-rails-49cfcd2fb190\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNH3Pquo_EhZuxCV7LvjXPoHnBeaRA&#39;;return true;">https://medium.com/badass-engineer/seo-friendly-urls-with-rails-49cfcd2fb190

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="WeppIQeiDAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">rubyonra...@googlegroups.com.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/rubyonrails-talk/1aa0ed3a-a906-4965-8ff1-c8fde1e909da%40googlegroups.com?utm_medium=email&amp;utm_source=footer" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/rubyonrails-talk/1aa0ed3a-a906-4965-8ff1-c8fde1e909da%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/rubyonrails-talk/1aa0ed3a-a906-4965-8ff1-c8fde1e909da%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/rubyonrails-talk/1aa0ed3a-a906-4965-8ff1-c8fde1e909da%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/36bef75c-1c04-4bdd-a43b-52194db1d431%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: ActiveRecord find ignores extra characters after numeric id. ?

fugee ohu
In reply to this post by Ariel Juodziukynas


On Wednesday, January 15, 2020 at 8:41:00 PM UTC-5, Ariel Juodziukynas wrote:
I insist, show your code, show the complete error stacktrace, show the log. I can imagine what you are trying to do and from the (little) code you show it should work so something else is messing things up but you are showing barely any relevant code.

El mié., 15 ene. 2020 a las 22:37, fugee ohu (<<a href="javascript:" target="_blank" gdf-obfuscated-mailto="WeppIQeiDAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">fuge...@...>) escribió:


On Wednesday, January 15, 2020 at 8:26:45 PM UTC-5, Ariel Juodziukynas wrote:
find method doesn't care about the to_param method, it just takes the parameter you use, I guess it calls "to_i" and uses that integer to query the id column

Why don't you show your code, the stacktrace, the logs or anything? I suggest you read something like stackoverflow's guidelines on how to ask, you posts are usually really hard to understand and a lot of information is missing

El mié., 15 ene. 2020 a las 18:01, fugee ohu (<[hidden email]>) escribió:


On Wednesday, January 15, 2020 at 3:07:00 PM UTC-5, Ariel Juodziukynas wrote:
From the docs: <a href="https://apidock.com/rails/v6.0.0/ActiveRecord/FinderMethods/find" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fapidock.com%2Frails%2Fv6.0.0%2FActiveRecord%2FFinderMethods%2Ffind\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHk5NLLhYgd7d5nLYxRp4OAkVps7A&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fapidock.com%2Frails%2Fv6.0.0%2FActiveRecord%2FFinderMethods%2Ffind\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHk5NLLhYgd7d5nLYxRp4OAkVps7A&#39;;return true;">https://apidock.com/rails/v6.0.0/ActiveRecord/FinderMethods/find

<a href="https://apidock.com/rails/Person" style="color:rgb(35,63,191)" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fapidock.com%2Frails%2FPerson\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNF4msDio5qDj8lVMu7J8TATciuEYw&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fapidock.com%2Frails%2FPerson\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNF4msDio5qDj8lVMu7J8TATciuEYw&#39;;return true;">Person.<a href="https://apidock.com/rails/ActiveRecord/FinderMethods/find" style="color:rgb(35,63,191)" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fapidock.com%2Frails%2FActiveRecord%2FFinderMethods%2Ffind\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNE4B-AvP-YwcXqN38gJXSTwhos52w&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fapidock.com%2Frails%2FActiveRecord%2FFinderMethods%2Ffind\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNE4B-AvP-YwcXqN38gJXSTwhos52w&#39;;return true;">find("31-sarah") # returns the object for ID = 31
In your case, if you are using find, it should search for record with id = 18

El mié., 15 ene. 2020 a las 16:18, fugee ohu (<[hidden email]>) escribió:
Doesn't work for me in rails 6

  Parameters: {"id"=>"18-test-title"}
 ActionController::ActionControllerError (Cannot redirect to nil!):

Ne

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/rubyonrails-talk/64e66550-c393-43cd-8156-29c43139899a%40googlegroups.com?utm_medium=email&amp;utm_source=footer" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/rubyonrails-talk/64e66550-c393-43cd-8156-29c43139899a%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/rubyonrails-talk/64e66550-c393-43cd-8156-29c43139899a%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/rubyonrails-talk/64e66550-c393-43cd-8156-29c43139899a%40googlegroups.com.

I've over-riding ActiveRecord to_param in my model

  def to_param
   "#{id}-#{title.parameterize}"
  end

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/rubyonrails-talk/1ba590e7-4c1c-4fcd-9ed8-0f2ed65b0350%40googlegroups.com?utm_medium=email&amp;utm_source=footer" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/rubyonrails-talk/1ba590e7-4c1c-4fcd-9ed8-0f2ed65b0350%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/rubyonrails-talk/1ba590e7-4c1c-4fcd-9ed8-0f2ed65b0350%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/rubyonrails-talk/1ba590e7-4c1c-4fcd-9ed8-0f2ed65b0350%40googlegroups.com.

I was trying to implement this guide:
<a href="https://medium.com/badass-engineer/seo-friendly-urls-with-rails-49cfcd2fb190" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fmedium.com%2Fbadass-engineer%2Fseo-friendly-urls-with-rails-49cfcd2fb190\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNH3Pquo_EhZuxCV7LvjXPoHnBeaRA&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fmedium.com%2Fbadass-engineer%2Fseo-friendly-urls-with-rails-49cfcd2fb190\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNH3Pquo_EhZuxCV7LvjXPoHnBeaRA&#39;;return true;">https://medium.com/badass-engineer/seo-friendly-urls-with-rails-49cfcd2fb190

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="WeppIQeiDAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">rubyonra...@googlegroups.com.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/rubyonrails-talk/1aa0ed3a-a906-4965-8ff1-c8fde1e909da%40googlegroups.com?utm_medium=email&amp;utm_source=footer" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/rubyonrails-talk/1aa0ed3a-a906-4965-8ff1-c8fde1e909da%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/rubyonrails-talk/1aa0ed3a-a906-4965-8ff1-c8fde1e909da%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/rubyonrails-talk/1aa0ed3a-a906-4965-8ff1-c8fde1e909da%40googlegroups.com.

So  what do you think is wrong with ensure_canonical_url ?

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/3b7d9ae7-2326-4ee1-991f-6e791d3bb35b%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: ActiveRecord find ignores extra characters after numeric id. ?

Ariel Juodziukynas
I guess you are calling ensure_canonical_url before_action BEFORE set_blog_post before_action, so it's not already set.

I guess you have something like:

before_action :ensure_canonical_url, only: :show
before_action :set_blog_post, only: :show

swap both lines if so.

El jue., 16 ene. 2020 a las 8:36, fugee ohu (<[hidden email]>) escribió:


On Wednesday, January 15, 2020 at 8:41:00 PM UTC-5, Ariel Juodziukynas wrote:
I insist, show your code, show the complete error stacktrace, show the log. I can imagine what you are trying to do and from the (little) code you show it should work so something else is messing things up but you are showing barely any relevant code.

El mié., 15 ene. 2020 a las 22:37, fugee ohu (<[hidden email]>) escribió:


On Wednesday, January 15, 2020 at 8:26:45 PM UTC-5, Ariel Juodziukynas wrote:
find method doesn't care about the to_param method, it just takes the parameter you use, I guess it calls "to_i" and uses that integer to query the id column

Why don't you show your code, the stacktrace, the logs or anything? I suggest you read something like stackoverflow's guidelines on how to ask, you posts are usually really hard to understand and a lot of information is missing

El mié., 15 ene. 2020 a las 18:01, fugee ohu (<[hidden email]>) escribió:


On Wednesday, January 15, 2020 at 3:07:00 PM UTC-5, Ariel Juodziukynas wrote:

Person.find("31-sarah") # returns the object for ID = 31
In your case, if you are using find, it should search for record with id = 18

El mié., 15 ene. 2020 a las 16:18, fugee ohu (<[hidden email]>) escribió:
Doesn't work for me in rails 6

  Parameters: {"id"=>"18-test-title"}
 ActionController::ActionControllerError (Cannot redirect to nil!):

Ne

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/64e66550-c393-43cd-8156-29c43139899a%40googlegroups.com.

I've over-riding ActiveRecord to_param in my model

  def to_param
   "#{id}-#{title.parameterize}"
  end

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/1ba590e7-4c1c-4fcd-9ed8-0f2ed65b0350%40googlegroups.com.

I was trying to implement this guide:

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/1aa0ed3a-a906-4965-8ff1-c8fde1e909da%40googlegroups.com.

So  what do you think is wrong with ensure_canonical_url ?

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/3b7d9ae7-2326-4ee1-991f-6e791d3bb35b%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAPS3bcDiB2WX6N_A6%3D3hOy6R%2B4V8mr8Dsp%2BDggE6QZ3LqCd5Jw%40mail.gmail.com.