全栈学习32天 11.17

我想做一个下拉框 思路代码,又错又丑

<%#= f.input :eat_venue, label: '约饭地点' %>
                  <%#= options_for_select(['Lisbon', 1], ['Madrid', 2]) %>
                  <%#= options_for_select([['Lisbon', 1, {'data-size' => '2.8 million'}], ['Madrid', 2, {'data-size' => '3.2 million'}]], 2) %>
                  <%#= f.label :eat_venue, "Status" %>
                  <%#= f.select :eat_venue, Subject::STATUS, {include_blank: "All status"}, class: "ui dropdown" %>
                  <%= select_tag(:eat_venue, '<option value="1">Lisbon</option> <option value="2">abc</option>') %>

                  <select name="city_id" id="city_id">
                   <option value="1">Lisbon</option>
                   <option value="2">Madrid</option>
                   <option value="12">Berlin</option>
                 </select>
 <%# address={"101咖啡"=>1,"汤城小厨"=>2,"星巴克"=>3} %>
                  <%#= options_for_select(address) %>
                  <p>约饭地点</p>
                  <%= select_tag(:eat_venue,
                    options_for_select([['101咖啡', 1],['汤城小厨', 2],['星巴克', 3]]),
                    ) %>                
                              

今天的任务还是续昨天的任务,修改约饭日期和约饭地址,时间只显示当前的周六和周日,地址为给写的地址
思路有了,搞了一天,地址功能丑一点,算是正常显示了,日期怎么试了一下午,加了一个字段eat_day_chooes,boole类型,周六为flase,周日为true,也能显示了,实在是一个大问题,不能显示具体的日期,于是又删除字段,重新再写,实在不有办法,只有求助同学,硕同学也忙了很久,后来xdite老师给一关键字end of this week,找到了根据日期找周日的方法。英文差,学开发的坑真大啊。
答案在哪里等你,你却怎么找都找不到她。
功能能显示就提交了,有一个小功能的bug,张同学一直帮我解,到了11点实在解不出来,又去问xidte老师。收获蛮大的。记录如下
Date type date
Time timetype 是string
在touch app/config/initializers/date.rb 用于周末判断

class Date
  def self.this_saturday
    Date.today.end_of_week()-1.days
  end

  def self.this_sunday
    Date.today.end_of_week()
  end
end

touch app/config/time_format.rb 用于Date的格式化

Date::DATE_FORMATS[:for_date] = "%Y/%m/%d"

在post定义一个方法,来保存我的地址

def self.default_location
    ["101咖啡", "汤城小厨", "星巴克", "USA"]
end

view new的写法

  <%= f.input :eat_venue, :collection => Post.default_location,
  :selected => Post.default_location[0],label: '约饭地点' %>
              <%= radio_button(:post, :eat_day,  Date.this_saturday,checked: true)%><strong>本周六<%=  Date.this_saturday.to_s(:for_date) %>
            <%= radio_button(:post, :eat_day ,  Date.this_sunday ) %><strong>本周日<%= Date.this_sunday.to_s(:for_date)  %></strong>
  

view edit写法

        <div class="group">
            <%= f.input :eat_venue, :collection => Post.default_location, :selected => @post.eat_venue,label: '约饭地点' %>
        </div>

        <div class="group">
            <p>约会日期</p>
            <%= radio_button(:post, :eat_day  ,Date.this_saturday )%>
            <strong>本周六<%= Date.this_saturday.to_s(:for_date) %></strong><br>
            <%= radio_button(:post, :eat_day ,Date.this_sunday) %>
            <strong>本周日<%= Date.this_sunday.to_s(:for_date) %></strong>
        </div>

在代码中<% #TODO ********* %>

在终端中运行rake notes会把这个内容打印出来,并报告位置

学习过程中,才体会,英语真的是钢需

Comments

comments powered by Disqus