Home>

The view file of rails is not readable, so I want to make it a form helper.

Please write your question in detail here.
Made the contents of the view file a form helper.
However, arrays such as ["10", "2010135152"] are displayed together and cannot be implemented well.
There are two problems, and it is difficult to implement. A reference article is fine. Please give me advice.

reducation_time wants to convert a number to time and display it.
I want to use integer type or string type.

Site ⇒ http://13.112.211.254/projects

Source code that I want to be a helper

View file code, dirty ...

  <% @ projects.each do | project |%>
      <tr>
        <td><% = project.id%></td>
        <td><% = link_to project.name, project_path (project)%></td>
        <td><% = project.status%></td>
        <td><% = project.number_of_month%>times</td>
        <td>
          <% if project.reducation_time>= 60%>
            <% = project.reducation_time/60%>time
            <% = project.reducation_time% 60%>minutes</td>
          <% else%>
            <% = project.reducation_time%>minutes
          <% end%>
        </td>
        <td>
          <% if project.number_of_month * project.reducation_time * 12>= 60%>
              <% = project.number_of_month * project.reducation_time * 12/60%>Time
              <% = project.number_of_month * project.reducation_time * 12% 60%>minutes</td>
            <% else%>
              <% = project.number_of_month * project.reducation_time * 12%>minutes
          <% end%>
<% end%>
What I tried

Try to put together in helper.rb

module ProjectsHelper
  def reducation_name
    project_id =''''
    @ projects.each do | project |
      project_id + = project.id.to_s
    end
    return raw (project_id)
  end
  def reducation
    reducation_hour =''''
    reducation_min =''
    @ projects.each do | project |
     if project.reducation_time>= 60
        reducation_hour + = (project.reducation_time/60) .to_s
        reducation_min + = (project.reducation_time% 60) .to_s
      else else
        reducation_min + = (project.reducation_time) .to_s
      end
    end
    binding.pry
    return raw (reducation_hour), raw (reducation_min)
  end
end

Trial take out with view file

<% = reducation%>
<% = reducation_name%>


View file
["10", "2010135152"]

Supplementary information (FW/tool version, etc.)

Rails 5.2.4.3

  • Answer # 1

    I feel that writing like this will give you the results you expect, but how about it?

    # Only the first ... I thought that product.reducation_time was displayed in minutes.
    <td>
    <% sec = project.reducation_time * 60%>
    <% = sec>= 3600? Time.at (sec) .strftime ('% H time% M minutes'): Time.at (sec) .strftime ('% M minutes')%>
    </td>

    Reference: https://marketing-web.hatenablog.com/entry/second_to_00-00-00