我对RoR很陌生,所以我应该错过一些东西 我一直试图在单击按钮时尝试通过Ajax加载弹出窗口 每次尝试达到此目标时,都会收到Ajax方法的错误,您可以在下面看到
我的JS方法:
TemplateField customField = new TemplateField();
customField.ItemTemplate = new GridViewTemplate(DataControlRowType.DataRow, "FirstName", ControlType.HyperLink);
customField.HeaderTemplate = new GridViewTemplate(DataControlRowType.Header, "First Name", ControlType.Label);
gv.Columns.Add(customField);
public class GridViewTemplate : ITemplate
{
private DataControlRowType templateType;
private ControlType controlType;
private string columnName;
public GridViewTemplate(DataControlRowType type, string colname, ControlType contType)
{
templateType = type;
columnName = colname;
controlType = contType;
}
public void InstantiateIn(System.Web.UI.Control container)
{
switch (templateType)
{
case DataControlRowType.Header:
Literal lc = new Literal();
lc.Text = "<b>" + columnName + "</b>";
container.Controls.Add(lc);
break;
case DataControlRowType.DataRow:
WebControl firstName = null;
switch (controlType)
{
case ControlType.Label:
firstName = new Label();
break;
case ControlType.HyperLink:
firstName = new HyperLink();
break;
default:
break;
}
firstName.DataBinding += new EventHandler(this.FirstName_DataBinding);
container.Controls.Add(firstName);
break;
}
}
private void FirstName_DataBinding(Object sender, EventArgs e)
{
GridViewRow row = null;
switch (controlType)
{
case ControlType.Label:
Label l = (Label)sender;
row = (GridViewRow)l.NamingContainer;
l.Text = DataBinder.Eval(row.DataItem, "FirstName").ToString();
break;
case ControlType.HyperLink:
HyperLink l2 = (HyperLink)sender;
row = (GridViewRow)l2.NamingContainer;
l2.Text = DataBinder.Eval(row.DataItem, "FirstName").ToString();
l2.NavigateUrl = "https://www.google.com";
break;
}
}
}
public enum ControlType
{
Label = 1,
HyperLink = 2
}
按钮代码:
function loadProgressForm(resource, id){
$(".form_loader").show();
if(resource == "new"){
url = "/progress_boards/new";
popup_name = "Make A Progress Board";
} else if (resource == "edit"){
url = "/progress_boards/" + id + "/edit";
popup_name = "Add/Remove Metrics";
} else if (resource == "pbbackground"){
url = "/progress_boards/" + id + "/pbbackground";
popup_name = "Add A Picture";
}
$.ajax({
url: url,
success: function(response, data){
$("#progress_board_form").html(response.html);
$("#progress_board_form").find('.modal-title').text(popup_name);
$(".form_loader").hide();
},
error: function(response, data){
alert("Error loading project form")
$(".form_loader").hide();
}
})
}
此外,这是与我的 %li= link_to 'Add Background', 'javascript:void(0)', onclick:"$('#create_edit_progress_board_model').appendTo('body').modal('show'); loadProgressForm('pbbackground', #{@progress_board.id});"
文件中的文件夹相对应的部分:
route.rb
答案 0 :(得分:0)
错误告诉您确切的问题所在:
ActionController::RoutingError (No route matches [GET] "/progress_boards/7/pbbackground")
而且,如您所见,您没有pbbackground
路线:
resources :progress_boards do
collection do
get :get_progress_data
get :get_panel_data
get :render_tab
end
member do
get :open_or_archive
end
end
假设您对pbbackground
执行了ProgressBoardsController
操作,然后执行以下操作:
resources :progress_boards do
collection do
get :get_progress_data
get :get_panel_data
get :render_tab
end
member do
get :open_or_archive
get :pbbackground
end
end
BTW和FWIW:Rails错误并非总是完全有用。但是,它们通常非常有用。在这种情况下,您会遇到RoutingError (No route matches)
错误。几乎可以肯定地指向您的routes.rb
。这与您的javascript或按钮代码无关。在这种情况下,显示您的JavaScript和按钮代码不相关。