Drop适用于#的href,但不适用于'home / index'

时间:2019-03-28 17:32:42

标签: ruby-on-rails bootstrap-4 ruby-on-rails-5.2

当我将#用作href值时,下拉菜单将起作用,但是当我具有链接时,下拉菜单将不起作用。

Bootstrap 4.3.1

我收到查询选择器错误:

  

SyntaxError:字符串与预期的模式不匹配。       所选元素

...

        <li class="nav-item dropdown">

              <a href="home/index" class="nav-link text-color-white dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"> 
                        Home
                    <i class="fa fa-search"></i>
                </a>
               <ul class="dropdown-menu" role="menu">
                 <li><a href="#" class="">Section 1</a></li>
                 <li><a href="#" class=""> Section 2</a></li>                    
                 <li><a href="#" class=""> Section 3</a></li>
               </ul>
            </li>

2 个答案:

答案 0 :(得分:1)

这是Bootstrap中的一个已知问题,他们正在修复其下一发行版。 Source

A solution (many solutions exist in this thread)

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.myApp.mobile.pm.payday"
        minSdkVersion 19
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "com.android.support:appcompat-v7:$rootProject.ext.supportLibraryVersion"
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

    implementation ("com.myApp.mobile.pm.common:app:$rootProject.ext.commonVersion") {
        exclude group: 'com.fasterxml.jackson.annotation'
        exclude group: 'com.fasterxml.jackson.core'
        exclude group: 'com.fasterxml.jackson.databind'
    }

    annotationProcessor "com.jakewharton:butterknife-compiler:$rootProject.ext.butterknifeVersion"
    annotationProcessor "android.arch.persistence.room:compiler:$rootProject.roomVersion"

}

下拉菜单需要一个ID,链接需要一个指向该ID的<li class="nav-item dropdown" id="parentDropdown"> <a href="home/index" class="nav-link text-color-white dropdown-toggle" data-toggle="dropdown" data-target="#parentDropdown" role="button" aria-expanded="false"> Home <i class="fa fa-search"></i> </a> <ul class="dropdown-menu" role="menu"> <li><a href="#" class="">Section 1</a></li> <li><a href="#" class=""> Section 2</a></li> <li><a href="#" class=""> Section 3</a></li> </ul> </li>

答案 1 :(得分:0)

在Ruby on Rails中,我们想声明一个链接,因此我们使用如下所示的内置link_to方法:

link_to(body, url, html_options = {})

在这种情况下,方法定义如下:

<%= link_to "Home", root_path, {class:"nav-link text-color-white dropdown-toggle", "data-toggle": "dropdown", role:"button", "aria-expanded": "false"} %>

来源:https://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html