链接未显示为按钮

时间:2017-10-15 01:20:28

标签: ruby-on-rails twitter-bootstrap sass actionview

在我的app / views / users / sessions / new.html.slim中,我有:

.container
  = form_for(resource, as: resource_name, url: session_path(resource_name), html: {class: "form-signin"}) do |f|
    h2.form-signin-heading
      = t('users.mailer.registrations.sessions.new.please_sign_in')
    .form-group
      .sr-only
        = f.label t('users.sessions.new.email_address')
      = f.email_field :email, class: 'form-control form-signin email_input', autofocus: true, placeholder: "Email Address", required: ""
      .sr-only
        = f.label t('users.sessions.new.password')
      = f.password_field :password, class: 'form-control form-signin password_input', autofocus: true, placeholder: "Password", required: ""
    - if devise_mapping.rememberable?
      .center-checkbox
        .form-check
          label.form-check-label
            = f.check_box :remember_me
            = t('users.sessions.new.remember_me')
    .form-group
      = f.submit t('users.mailer.sessions.new.log_in'), class: "btn btn-lg btn-primary btn-block"
    = render "devise/shared/links"

在我的app / views / users / shares / _links.html.sim中,我有:

- if controller_name != 'sessions'
  .form-group
    = link_to t('users.shared._links.log_in'), new_session_path(resource_name), class: "btn btn-lg btn-primary btn-block"
    br
- if devise_mapping.registerable? && controller_name != 'registrations'
  .form-group
    = link_to t('users.shared._links.sign_up'), new_registration_path(resource_name), class: "btn btn-lg btn-primary btn-block"
    br
- if devise_mapping.recoverable? && controller_name != 'passwords' && controller_name != 'registrations'
  .form-group
    = link_to t('users.shared._links.forgot_password'), new_password_path(resource_name), class: "btn btn-lg btn-primary btn-block"
    br
- if devise_mapping.confirmable? && controller_name != 'confirmations'
  .form-group
    = link_to t('users.shared._links.no_confirmation_instructions'), new_confirmation_path(resource_name), class: "btn btn-lg btn-primary btn-block"
    br
- if devise_mapping.lockable? && resource_class.unlock_strategy_enabled?(:email) && controller_name != 'unlocks'
  .form-group
    = link_to t('users.shared._links.no_unlock_instructions'), new_unlock_path(resource_name), class: "btn btn-lg btn-primary btn-block"
    br
- if devise_mapping.omniauthable?
  .form-group
    - resource_class.omniauth_providers.each do |provider|
      = link_to "#{t('users.shared._links.sign_in_with')} #{OmniAuth::Utils.camelize(provider)}", omniauth_authorize_path(resource_name, provider), class: "btn btn-lg btn-primary btn-block"
      br

在我的assets / stylesheets / signin.css.scss中,(我将其导入applicatio.css.scss),我有:

.form-signin {
  max-width: 330px;
  padding: 15px;
  margin: 0 auto;
}
.form-signin body {
  padding-top: 40px;
  padding-bottom: 40px;
  background-color: #ee
}
.form-signin .form-signin-heading,
.form-signin .center-checkbox {
  text-align: center;
  margin-bottom: 10px;
}
.form-signin .form-control {
  position: relative;
  height: auto;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  padding: 10px;
  font-size: 16px;
}
.form-signin .form-control:focus {
  z-index: 2;
}
.form-signin .email_input {
  margin-bottom: -1px;
  border-bottom-right-radius: 0;
  border-bottom-left-radius: 0;
}
.form-signin .password_input {
  margin-bottom: 10px;
  border-top-left-radius: 0;
  border-top-right-radius: 0;
}

而不是按钮,对于共享链接,这是我得到的:

enter image description here

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

link_to生成<a>标记,该标记不是button type="button"。你应该使用的应该是button_to例如 -

= button_to t('users.shared._links.log_in'), new_session_path(resource_name),:class => "btn btn-lg btn-primary btn-block", :method => :get 

您只需要添加:method => "get",就可以从路线中获取您的方法类型,直到button_to的末尾,以便将其视为链接

谢谢。