2010-12-25 14 views
4

私はRailsでauthlogic-connectを使用しています。私はすでに追加されている認可プロバイダを表示したくない単純なhamlテンプレートを使用しています。タイプが一致しません:文字列が指定されました - ルビーの文字列に一致しようとしています

%h2 My Account 
%form.authentication_form{:action => connect_path, :method => :post} 
    %fieldset 
    %input{:type => :hidden, :name => :authentication_type, :value => :user} 
    %legend Add another Oauth or OpenID provider. 
    .oauth_providers 
     %ul 
     - %w(google facebook twitter yahoo).each do |name| 
      %li.oauth_provider 
      -unless "{user.authenticated_with}" =~ "{name}" 
       %img{:src => "/images/icons/#{name}.png"} 
       %input{:type => :radio, :id => "#{name}_oauth_provider", :name => :oauth_provider, :value => name} 
     .clearfix 
    %input.submit{:name => :submit, :type => :submit, :value => "Update"}/ 

エラータイプが不一致:文字列に遭遇しました。 user.authenticated withは文字列を返します。

def authenticated_with 
     @authenticated_with ||= self.access_tokens.collect{|t| t.service_name.to_s} 
    end 

考えられる問題は何ですか?

スタックトレース:

ActionView::Template::Error (type mismatch: String given): 
    7:  %ul 
    8:   - %w(google facebook twitter yahoo).each do |name| 
    9:   %li.oauth_provider 
    10:    -unless "{user.authenticated_with}" =~ "{name}" 
    11:    %img{:src => "/images/icons/#{name}.png"} 
    12:    %input{:type => :radio, :id => "#{name}_oauth_provider", :name => :oauth_provider, :value => name} 
    13:   .clearfix 
    app/views/users/edit.html.haml:10:in `=~' 
    app/views/users/edit.html.haml:10:in `_app_views_users_edit_html_haml___2062853011_2171399360_0' 
    app/views/users/edit.html.haml:8:in `each' 
    app/views/users/edit.html.haml:8:in `_app_views_users_edit_html_haml___2062853011_2171399360_0' 

抽出されたソース(ライン#10の周り): - ライン10

+0

ポストエラーを報告している行を特定する。 – Zabba

+0

@Zabbaがスタックトレースを提供した。 – Arc

+0

なぜ、 'user.authenticated_with == name'の代わりに' =〜 'を使うのですか? – tokland

答えて

12

上のエラーがString#=~に引数として正規表現を渡して表示:

>> string = "el" 
>> "hello" =~ /#{string}/ 
=> 1 
関連する問題