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

Writing a test for my project and notification of this warning about its end when rspec starts

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 recording a save, it looks like

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

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

** EDIT **

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

Than I decided to go the other way and changed to "#{theme}(#{date})" . The date method is as follows:

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

But that still gives me an error.

I do not think that this is really a big problem, but still I want to understand why this is happening.

** EDIT **

Explain this, it should fix that I am using the cause of this problem (the gem is called the_string_to_slug ). I will do further research to fix this warning with a gem, or I will try to find a way to replace it.

+7
ruby ruby-on-rails
source share
3 answers

This variation was deleted 10 days ago. https://github.com/rails/rails/commit/0189f4db6fe518de8909b66b7f30046bac52dedc

Perhaps one of the stones uses the old format of the parameterize method.

+1
source share

Try this instead

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

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

+1
source share

DEPARTMENT WARNING: Passing the delimiter argument as a positional parameter is deprecated and will be deleted soon. Use separator: '-' instead.

This tells you not to paste it directly into your string, but to pass a hash of the parameters or the separator: '-' keyword separator: '-' instead of your method instead of line 37 of your Post model.

0
source share

All Articles