渲染:更新do | page |与Rails3.X无法正常工作

时间:2012-08-22 22:08:17

标签: ruby-on-rails ruby ruby-on-rails-3 rjs

我的routes.rb中有以下内容:

  match 'admins/approve' => 'admins#approve', :as => :admins_approve, :method => :post

在我的admins_controller.rb中,我有:

def approve
  render :update do |page|
      page << "alert(" + params[:note] + ");"  
  end           
end

在我的admins / index.html.erb中:

<% @users.each do |user| %>
  <tr>
    <td class= "action_add_note">
        <%= form_tag admins_approve_path, :id => "form_note_#{user.id}", :remote=> true  do %> 
          <%= text_area_tag 'note' %>
        <% end %>
        <%= link_to_function content_tag(:i, "", :class => 'icon-ok' ), 
                  "$('#form_note_#{user.id}').submit();", :class => "btn"%>
    </td>
  </tr>
<% end %>

我知道我可以使用按钮而不是功能但这不是这里的情况,无论如何,无论何时我提交它我都会错误的路径以及以下错误:

ActionView::MissingTemplate (Missing template admins/update, application/update with {:locale=>[:en], :formats=>[:js, "application/ecmascript", "application/x-ecmascript", :html, :text, :js, :css, :ics, :csv, :png, :jpeg, :gif, :bmp, :tiff, :mpeg, :xml, :rss, :atom, :yaml, :multipart_form, :url_encoded_form, :json, :pdf, :zip], :handlers=>[:erb, :builder, :coffee]}. Searched in:
* "/Users/Apple/code/rails_pp/app/views"
* "/Users/Apple/.rvm/gems/ruby-1.9.2-p180/gems/twitter-bootstrap-rails-2.1.1/app/views"
app/controllers/admins_controller.rb:11:in `approve'

Rendered /Users/Apple/.rvm/gems/ruby-1.9.2-p180/gems/actionpack-3.2.6/lib/action_dispatch/middleware/templates/rescues/missing_template.erb within rescues/layout (0.6ms)

1 个答案:

答案 0 :(得分:1)

取出link_to_function并将其添加到您的form_tag

<%= text_area_tag 'note' %>
<%= submit_tag "Submit %>
 <% end %>

在您的管理员控制器

def approve
  @note = params[:note]
  current_user.update_attribute(:note, @note)
  respond_to do |format|
    format.js
  end
end

然后创建approve.js.erb文件

 alert("<%= j(@note) %>");