问题描述
我要通过单击提交标记加载模态对话框。但是当我按一下按钮,就直接去了页面,无需去RJS文件中,并没有呈现部分。以下是我的code。
I want to load a modal dialog box by clicking submit tag. but when I click on the button, it directly went to page without going to rjs file and did not render partial.following is my code.
<span style="text-align: right">
<% form_tag "/calendar/dia_cal_view" do %>
<%= collection_select("event", "trainer_id", @trainers , :id, :name, {:prompt => true}) %>
<%= submit_tag "search" %>
<%end%>
</span>
控制器code:
controller code:
def dia_cal_view
@month = (params[:month] || (Time.zone || Time).now.month).to_i
@year = (params[:year] || (Time.zone || Time).now.year).to_i
@shown_month = Date.civil(@year, @month)
@trainers=Trainer.all
@first_day_of_week = 1
if session[:dia_Serach].nil?
if (defined? (params[:event][:trainer_id]))
session[:dia_Serach]=(params[:event][:trainer_id])
#@@id=(params[:event][:trainer_id])
@event_strips = Event.event_strips_for_month(@shown_month, @first_day_of_week, :conditions=>["trainer_id = ?",session[:dia_Serach]])
else
@event_strips = Event.event_strips_for_month(@shown_month, @first_day_of_week)
end
else
@event_strips = Event.event_strips_for_month(@shown_month, @first_day_of_week, :conditions=>["trainer_id = ?",session[:dia_Serach]])
end
end
dia_cal_view.js.rjs
dia_cal_view.js.rjs
page.replace_html 'search_result', :partial => 'cal_view'
page<< "$j ('#search_result_dialog').dialog({
title: 'calendar',
modal: true,
width: 500,
height: 500,
close: function(event, ui) { $j ('#search_result_dialog').dialog('destroy') }
});"
_cal_view.html.erb
_cal_view.html.erb
<%= stylesheet_link_tag "event_calendar" %>
<%= event_calendar %>
问题是,RJS文件没有工作。它没有去RJS文件。我应该怎么做呢? plz帮助我..
The problem is that rjs file did not work. It did not go to rjs file. what should I do for this? plz help me..
推荐答案
首先所有的表单提交作为HTML而不是作为一个RJS请求。首先,您需要更改到RJS要求,改变这一行
first of all your form is submitted as a html and not as a rjs request.You first need to change that to rjs request, change this line
<% form_tag "/calendar/dia_cal_view" do %>
使用
remote_form_tag
或选项
远程=真
根据您的轨道版本
这应该工作,那么
这篇关于负载RJS文件,通过点击提交Rails的标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!