0

我的 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

在我的管理员/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)
4

1 回答 1

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) %>");
于 2012-08-22T22:43:56.137 回答