我的路线中有以下内容。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)
取出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) %>");