2011-12-20 1 views
0

date_select가있는 간단한 일반 레일스 양식이 제공됩니다 (다른 필드 중에서도 코드에서 해당 필드를 제거했습니다).Rails 3.1 및 Coffeescript : 날짜를 설정하는 링크를 추가하십시오.

어제, 오늘, 내일, ..., 다음 주 이름의이 양식에 대한 링크를 추가하고 싶습니다. 이 링크 중 하나를 클릭하면 date_select를 올바른 날짜로 설정해야합니다 (양식 제출 없음).

너무 많은 Javascript 번거 로움없이 Rails 3에서 이것을 수행하는 가장 좋은 방법은 무엇입니까?

<%= form_for(@entry) do |f| %> 
<% if @entry.errors.any? %> 
<div id="error_explanation"> 
    <h2><%= pluralize(@entry.errors.count, "error") %> prohibited this entry from being saved:</h2> 

    <ul> 
    <% @entry.errors.full_messages.each do |msg| %> 
    <li><%= msg %></li> 
    <% end %> 
    </ul> 
</div> 
<% end %> 

<div class="field"> 
    <%= f.label "Datum" %><br /> 
    <%= f.date_select :datum %> 
</div> 
.... 

답변

0

보기

<div> 
    Set date to: <span class="test"><%= Date.today.to_s %></span> 
</div> 

entries.js.coffee.erb

$ -> 
    $('.test').bind 'click', -> 
    text = $(this).text() 
    $("#date_entry").val(text)