Ruby on rails 使用Rails 3中的简单导航gem在渲染时显示正确的菜单:创建
我正在Rails 3应用程序中使用简单的导航gem。除了一个小怪癖外,它工作得很好 我有一个侧边栏div,它包含第二级菜单,显示的是Ruby on rails 使用Rails 3中的简单导航gem在渲染时显示正确的菜单:创建,ruby-on-rails,menu,navigation,Ruby On Rails,Menu,Navigation,我正在Rails 3应用程序中使用简单的导航gem。除了一个小怪癖外,它工作得很好 我有一个侧边栏div,它包含第二级菜单,显示的是!渲染导航(:level=>2).nil? 除了一种特殊情况外,它工作正常。假设我有一个模型。一个普通用户(即使他们没有登录)能够创建一个新的联系人尝试,在controller I中保存记录,然后向适当的部门发送通知电子邮件。 此外,管理员可以列出所有记录(索引)并查看每个记录(显示),编辑和更新被禁用。这只是一个联系表单,除了恶意原因之外,不需要编辑或更新记录 下
!渲染导航(:level=>2).nil?
除了一种特殊情况外,它工作正常。假设我有一个模型。一个普通用户(即使他们没有登录)能够创建一个新的联系人尝试,在controller I中保存记录,然后向适当的部门发送通知电子邮件。
此外,管理员可以列出所有记录(索引)并查看每个记录(显示),编辑和更新被禁用。这只是一个联系表单,除了恶意原因之外,不需要编辑或更新记录
下面是如何设置我的导航(从navigation.rb)
我的问题是,当用户试图提交未通过验证的信息时(如未返回电子邮件或包含非法字符的消息),表单会再次呈现,并显示所有错误。但是,即使当前的操作==“create”
,实际的url也会变成“本地主机:3000次/联系\u次尝试
。这意味着对于simple-navigation,路径看起来像是contact\u attempt\u path,而secondary.item:不会生成new\u contact\u attempt。我尝试使用highlights\u on=>/contact\u尝试
来解决这个问题,它强制在所有视图上生成项目,但是在所有操作上它总是高亮显示,这很混乱
有人知道怎么解决吗
编辑
好的,我能够找到一种方法来实现我想要的——但它看起来很麻烦,我真的不喜欢它:
primary.item :contact_us, 'Contact Us', new_contact_attempt_path do |secondary|
if user_signed_in? and current_user.admin?
if params[:action] == ("create" or "new" )
secondary.item :send_email, 'Send Email', new_contact_attempt_path, :highlights_on => /contact_attempts/
secondary.item :list_contact_attempts, 'List of Contact Attempts', contact_attempts_path, :highlights_on => /contact_attempts\/index/
else
secondary.item :send_email, 'Send Email', new_contact_attempt_path
secondary.item :list_contact_attempts, 'List of Contact Attempts', contact_attempts_path
end
else
secondary.item :send_email, 'Send Email', new_contact_attempt_path, :highlights_on => /contact_attempts/
end
end
primary.item :contact_us, 'Contact Us', new_contact_attempt_path do |secondary|
if user_signed_in? and current_user.admin?
if params[:action] == ("create" or "new" )
secondary.item :send_email, 'Send Email', new_contact_attempt_path, :highlights_on => /contact_attempts/
secondary.item :list_contact_attempts, 'List of Contact Attempts', contact_attempts_path, :highlights_on => /contact_attempts\/index/
else
secondary.item :send_email, 'Send Email', new_contact_attempt_path
secondary.item :list_contact_attempts, 'List of Contact Attempts', contact_attempts_path
end
else
secondary.item :send_email, 'Send Email', new_contact_attempt_path, :highlights_on => /contact_attempts/
end
end
如果没有人回来提出正确的解决方案,我会把这个标记为明天回答-(好的,我找到了一种实现我想要的东西的方法——但是它看起来很麻烦,我真的不喜欢它:
primary.item :contact_us, 'Contact Us', new_contact_attempt_path do |secondary|
if user_signed_in? and current_user.admin?
if params[:action] == ("create" or "new" )
secondary.item :send_email, 'Send Email', new_contact_attempt_path, :highlights_on => /contact_attempts/
secondary.item :list_contact_attempts, 'List of Contact Attempts', contact_attempts_path, :highlights_on => /contact_attempts\/index/
else
secondary.item :send_email, 'Send Email', new_contact_attempt_path
secondary.item :list_contact_attempts, 'List of Contact Attempts', contact_attempts_path
end
else
secondary.item :send_email, 'Send Email', new_contact_attempt_path, :highlights_on => /contact_attempts/
end
end
primary.item :contact_us, 'Contact Us', new_contact_attempt_path do |secondary|
if user_signed_in? and current_user.admin?
if params[:action] == ("create" or "new" )
secondary.item :send_email, 'Send Email', new_contact_attempt_path, :highlights_on => /contact_attempts/
secondary.item :list_contact_attempts, 'List of Contact Attempts', contact_attempts_path, :highlights_on => /contact_attempts\/index/
else
secondary.item :send_email, 'Send Email', new_contact_attempt_path
secondary.item :list_contact_attempts, 'List of Contact Attempts', contact_attempts_path
end
else
secondary.item :send_email, 'Send Email', new_contact_attempt_path, :highlights_on => /contact_attempts/
end
end
如果没有人回来提出正确的解决方案,我会把这个标记为明天回答-(
现在似乎是最好的解决方案,因为它没有在gem中实现。在github上为andi(创建者)打开了一张罚单。好的,我能够找到一种实现我想要的方法-但它看起来很麻烦,我真的不喜欢它:
primary.item :contact_us, 'Contact Us', new_contact_attempt_path do |secondary|
if user_signed_in? and current_user.admin?
if params[:action] == ("create" or "new" )
secondary.item :send_email, 'Send Email', new_contact_attempt_path, :highlights_on => /contact_attempts/
secondary.item :list_contact_attempts, 'List of Contact Attempts', contact_attempts_path, :highlights_on => /contact_attempts\/index/
else
secondary.item :send_email, 'Send Email', new_contact_attempt_path
secondary.item :list_contact_attempts, 'List of Contact Attempts', contact_attempts_path
end
else
secondary.item :send_email, 'Send Email', new_contact_attempt_path, :highlights_on => /contact_attempts/
end
end
primary.item :contact_us, 'Contact Us', new_contact_attempt_path do |secondary|
if user_signed_in? and current_user.admin?
if params[:action] == ("create" or "new" )
secondary.item :send_email, 'Send Email', new_contact_attempt_path, :highlights_on => /contact_attempts/
secondary.item :list_contact_attempts, 'List of Contact Attempts', contact_attempts_path, :highlights_on => /contact_attempts\/index/
else
secondary.item :send_email, 'Send Email', new_contact_attempt_path
secondary.item :list_contact_attempts, 'List of Contact Attempts', contact_attempts_path
end
else
secondary.item :send_email, 'Send Email', new_contact_attempt_path, :highlights_on => /contact_attempts/
end
end
如果没有人回来提出正确的解决方案,我会把这个标记为明天回答-(
似乎是目前最好的解决方案,因为它没有在gem中实现。在github上为andi(创建者)打开了一张票据