我有一个名为 crumbs 的方法,它说的是未定义的方法。我正在从 sinatra 应用程序导入代码并尝试使其与 rails 应用程序一起使用。
这是方法:
def crumbs
primary, secondary = current_link
return {
primary: { icon: menu[primary.to_sym][:primary][:icon], label: menu[primary.to_sym][:primary][:label]},
secondary: {
icon: menu[primary.to_sym][:items][secondary.to_sym][:icon],
label: menu[primary.to_sym][:items][secondary.to_sym][:label]
}
}
end
以下是该方法中包含的其他方法:
def menu
return {
dashboard: {
primary: { link: "dashboard", icon: "icon-dashboard", label: "Dashboard" },
items: {
dashboard: { icon: "icon-dashboard", label: "Dashboard" }
}
},
ui_lab: {
primary: { link: "buttons", icon: "icon-beaker", label: "UI Lab" },
items: {
buttons: { icon: "icon-hand-up", label: "Buttons" },
general: { icon: "icon-beaker", label: "General elements" },
icons: { icon: "icon-info-sign", label: "Icons"},
grid: { icon: "icon-th-large", label: "Grid"},
tables: { icon: "icon-table", label: "Tables"},
widgets: { icon: "icon-plus-sign-alt", label: "Widgets"},
}
},
forms: {
primary: { link: "forms", icon: "icon-edit", label: "Forms" },
items: {
forms: { icon: "icon-edit", label: "Form Elements" }
}
},
charts: {
primary: { link: "charts", icon: "icon-bar-chart", label: "Charts"},
items: {
charts: { icon: "icon-bar-chart", label: "Charts"}
}
},
other: {
primary: { link: "wizard", icon: "icon-link", label: "Others"},
items: {
wizard: { icon: "icon-magic", label: "Wizard" },
login: { icon: "icon-user", label: "Login Page" },
sign_up: { icon: "icon-user", label: "Sign Up Page" },
full_calendar: { icon: "icon-calendar", label: "Full Calendar" },
error404: { icon: "icon-ban-circle", label: "Error 404 page" },
}
}
}
end
还有这个:
def current_link
root_path = "/"
current_route = request.url.split("/") # pages/dashboard/stats.html -> ['dashboard', 'stats.html']
return current_route.compact.first, current_route.compact.split(".").first
end
在视图中,这就是所谓的:
<i class="<%= crumbs[:secondary][:icon] %>"></i>
<%= crumbs[:secondary][:label] %>
有任何想法吗?