在rails 4中的popover内部渲染部分编辑表单

时间:2015-05-27 20:29:07

标签: javascript jquery ruby-on-rails twitter-bootstrap popover

大家好我真的需要帮助。 我正在制作一个待办事项应用程序并通过迭代显示每个任务。在每个任务旁边,我都有一个铅笔glyphicon。

当我点击它时,我希望有一个包含编辑表单的弹出框,并在现场编辑任务。我有很多令人不安的渲染形式。 *****更新***** 克拉克帮助我让popover工作。但是popover中的表单就像一个链接而不是一个表单,因此我无法输入文本区域。

这是我的index.html.erb

    <div id='user_tasks'>
  <% @tasks.each do |task| %>
    <ul>
        <li>
        <%= task.description %>
      <%= link_to edit_task_path(task), :rel => 'popover', method: 'get', remote: 'true' do %> 
      <span class = 'edit_task_<%=task.id%> glyphicon glyphicon-pencil'> </span>
      <% end %>
        </li>
    </ul>
  <% end %> 
</div>    

这是edit.js.erb

     $(function(){
         $('.edit_task_<%=@task.id%>').popover({
         html: true,
         title: 'edit',
         content: <%= escape_javascript render 'edit_form', task:@task %> 
           }).popover('show'); });

我的控制器看起来像这样:

  def index
    @new_task= Task.new
    @tasks= Task.all    
  end

  def create
    @new_task= Task.new(task_params)
    @task.save
    redirect_to :back   
  end

  def edit
    @task= Task.find(params[:id])   
  end

_edit_form.html.erb看起来像这样:这不是我打算使用的编辑表单。它只是创建任务表单的副本。我计划在弹出窗口工作后修复它。

    <%= form_for task, :html=>{:class=> 'form-inline'} do |f| %>
  <div class='form-group'>
    <%= f.text_field :description, placeholder: 'create a task' %>
    <%= button_tag(type:'submit', class:"btn btn-default btn-xs") do %>
      <span class='glyphicon glyphicon-plus'></span>
    <% end %>
  </div>
<% end %>

0 个答案:

没有答案
相关问题