我想创建一个随机选择生成器,应该使用<%= button_to("Randomize someting to do!", {:action => "random_task"}) %>
这个调用方法的按钮来调用它random task
def random_task
x = rand(Task.first.id..Task.last.id)
@task = Task.find(x)
rescue ActiveRecord::RecordNotFound => e
random_task
respond_to do |format|
format.html { render @task}
format.json { head :no_content }
end
end
这应该回调我的 view/random_task.html.erb
<div class="field">
<%= f.label :name %><br />
<%= f.text_field :name,:disabled=>true %>
</div>
<div class="field">
<%= f.label :category %><br />
<%= f.text_field, :category,:disabled=>true %>
</div>/tasks/
<div class="field">
<%= f.label :points %><br />
<%= f.number_field :points,:disabled=>true %>
</div>
<div class="rank_buttons">
<%= link_to 'Vote up', :action => 'rate_up', :id => task.id %>
<%= link_to 'Vote down', :action => 'rate_down', :id => task.id %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
编辑问:如果写得好,我如何正确调用渲染表单?