开发者

Rails show X image if Case reference is M10-XXX?

I currently have a model that the user can upload a thumbnail to the record which is then shown on the show view page. This thumbnail was originally intended so the user could easily find the case when searching through the index view table of records.

It has become apparent that users are only using this function to upload a thumbnail of the year - for example, they have uploaded a red square with 10 in for each case with a reference number of M10-X开发者_如何学运维XX.

So I was wondering if it's possible to add a helper to the kase model to output an image if the kase reference starts with M10. I could then include in the same helper the image for 2011, 2012 and so on.

At the moment the kase show view calls the uploaded thumbnail:

<% if @kase.avatar.exists? then %>
            <%= image_tag @kase.avatar.url %>
        <% else %>
            <img src="../images/document.jpg" alt="Document" />
        <% end %>

What I would like to do, is add a helper such as:

def kase_thumb k 
  if k.jobno.to_date == Date.today then
    <img src="images/10.png" alt="2010" />
  else 
    <img src="images/no-year-found.png" alt="2010" />
  end
end

Obviously the above wouldn't work because the standard jobno would be M-XXX where is replaced with the last two digits of the current year.

Is is possible to have a helper method that extracts the first two numbers, but ignores the first letter?

I did think about doing this with the date created, but people may retrospectively add cases to the application.

Thanks,

Danny


Given the string of the case number/identifier:

number = the_case_id[1,2].to_i

Hope this helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜