Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby/Rails: Use `separator: '-'` instead

Writing test for my project, and notice this warning it terminal when running rspec

DEPRECATION WARNING: Passing the separator argument as a positional
parameter is deprecated and will soon be removed. 
Use `separator: '-'` instead.
(called from add_link at /myapp/app/models/post.rb:37)

I have an action before save record, looks like

self.link = theme + '-' + Time.now.to_formatted_s(:number)

And I've tried to find some information about this but I don't really don't understanding what this warning means.

** EDIT **

Well, I've changed for "#{theme}-#{Time.now.to_formatted_s(:number)}" but it still gives me the same warning.

Than I decided to go other way and changed for "#{theme}(#{date})". The date method look like:

date = [Time.now.day, Time.now.month, Time.now.year]
date = date.join('-')
date

But it still gives me an error.

I don't think it's really big problem, but still I want t figure out why is that happening.

** EDIT **

Figure it out, it must gem that I use cause that problem (the gem is called the_string_to_slug) I will do future research to fix this warning with gem or I'll try to find way to replace it.

like image 408
Andrey Drozdov Avatar asked Nov 23 '16 21:11

Andrey Drozdov


2 Answers

This deprecation was removed 10 days ago. https://github.com/rails/rails/commit/0189f4db6fe518de8909b66b7f30046bac52dedc

Probably one of gems use old format of parameterize method.

like image 50
Alex Kojin Avatar answered Sep 18 '22 12:09

Alex Kojin


Try this instead

parameterize("Donald E. Knuth", separator: '_') # => "donald_e_knuth"

http://www.rubydoc.info/gems/activesupport/5.0.0/ActiveSupport%2FInflector%3Aparameterize

like image 30
mountriv99 Avatar answered Sep 18 '22 12:09

mountriv99