Question: I apologize for the title, it makes little to no sense.

So on my messages.rb model I am using:

```
def to_param
    "#{id}-#{message.gsub(/\W/, '-').downcase}"
end

```

to make it so the url wills show up like so:

<http://myapp.com/messages/1-this-is-a-message>

The problem with this is, when the message is really long, and on live, it causes the app to crash.

How can I change this to\_params function to limit the number of characters that will show up in the url to the first 25 or so.

Thanks!

Answer: 
Use the String object's [`slice`](http://ruby-doc.org/core/classes/String.html#M000843) method or `[]` notation: (`[]` is just an alias to `slice`)

```
def to_param
   "#{id}-#{message[0..25].gsub(/\W/, '-').downcase}"
end

```
```
 def to_param
     "#{id}-#{truncate(message, :length => 40).gsub(/\W/, '-').downcase}"
 end

```

You can use Rails's truncate helper:

```
truncate(message, :length => 40)

```

message is your message of course and you can specify your length