0

in my view i have the following:

<% @files.each do |f| -%>
    <% str = f.split("#{RAILS_ROOT}/public/downloads/") %>
    <% =str% ><br>
<% end -%>

each file name that is output is preceeded by "/public/downloads/". i have tried numerous functions but can't seem to find a function that works to get rid of it.

Thanks.

1
  • What does @files array consist of? Commented Jan 27, 2011 at 12:57

2 Answers 2

2

Have you tried basename?

Pathname.new(str).basename.to_s

update:

<% @files.each do |f| -%>
    <% str = Pathname.new(f).basename.to_s %>
    <%= str %><br>
<% end -%>
Sign up to request clarification or add additional context in comments.

1 Comment

tried so many variations... getting "can't convert Array into String" to this and other variations: newstr = Pathname.new(str).basename.to_s
1

This should work:

<% @files.each do |f| -%>
<% str = f.gsub(/^.*\//, '') %>
<% =str% ><br>
<% end -%>

2 Comments

hi psyho. this produces the same results including "/public/downloads/" prior to the file name. thanks tho.
that works perfectly. read up on gsub and could not get it to work myself. with the regexp you supplied... i think i understand how it works now. thanks!

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.