0

Let's say I have this route:

get 'post/:title' => 'post#show' , :as => 'show_post'

Anyone is able to create posts, and pick their own titles. I don't want the title to contain characters like '/', '[', ']' as it could lead to bad urls generated with the helper method show_post_path('blah'). I'm sure there are other things than those character I mentioned I should be looking out for.

I'm looking for a way to validate against this in the post model.

/ Thanks

2 Answers 2

3

You can use Rails parameterize method to validate the string Ex-

result = yourstring.parameterize

here is source http://apidock.com/rails/ActiveSupport/Inflector/parameterize

Sign up to request clarification or add additional context in comments.

Comments

2

I think the best way to make it will be use gem friendly_id

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.