LoadError:无法加载此类文件--bcrypt

时间:2017-05-13 19:12:04

标签: ruby-on-rails rubygems

我正在尝试使用bcrypt来保护用户密码,但是当我在数据库中创建新用户时,我收到此错误:“LoadError:无法加载此类文件 - bcrypt”

到目前为止我做了什么:

  1. 我在Gemfile中放置了一个gem sudo bundler install

  2. 我安装了它 $ gem list bcrypt *** LOCAL GEMS *** bcrypt (3.1.11)

  3. bcrypt在宝石列表中

  4. $ rails console 
    Running via Spring preloader in process 21100
    Loading development environment (Rails 5.1.0)
    irb(main):001:0> User.create(username: "user1" , password: "pass123", password_confirmation: "pass123")
    You don't have bcrypt installed in your application. Please add it to your Gemfile and run bundle install
    LoadError: cannot load such file -- bcrypt
            from app/models/user.rb:2:in `<class:User>'
            from app/models/user.rb:1:in `<top (required)>'
            from (irb):1
    
    1. 我已重新启动服务器
    2.   

      sudo service apache2 restart

      1. 我在rails console中添加了新用户
      2. bcrypt-ruby

        正如你所看到的那样无效!

        1. 我尝试再次卸载并安装bcrypt =&gt;相同的结果

        2. 我尝试过其他版本的bcrypt =&gt;相同的结果

        3. 我将install bcrypt --platform=ruby添加到gems =&gt;相同的结果
        4. 我使用了gem gem 'bcrypt-ruby', '3.1.5', :require => 'bcrypt'cd [path to gems folder]/gems/bcrypt-ruby-2.1.4/ext/mri ruby extconf.rb make sudo make install =&GT;相同的结果
        5. 我更新了所有gems =&gt;相同的结果
        6. 我手动构建了本机扩展程序
        7. public class UEC extends AppCompatActivity {
          
          List<SavePlace> userInfo;
          
          String name;
          boolean flag;
          SharedPreferences sharedPref;
          
          public UEC(SharedPreferences sharedPref){
              this.sharedPref = sharedPref;
          }
          
          @Override
          protected void onCreate(@Nullable Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
          }
          
          public boolean checkIfUserExists() {
          
              email = sharedPref.getString("userEmail", "");
          
              Retrofit retrofitCheckUser = ApiClientSavePlace.getClient();
              ApiInterfaceSavePlace apiInterfaceSavePlace = retrofitCheckUser.create(ApiInterfaceSavePlace.class);
              final Call<List<SavePlace>> checkUser = apiInterfaceSavePlace.getSavePlaces();
          
              checkUser.enqueue(new Callback<List<SavePlace>>() {
                  @Override
                  public void onResponse(Call<List<SavePlace>> call, Response<List<SavePlace>> response) {
                      userInfo = response.body();
                      try {
                          if(userInfo.size()!=0){
                              for (int i = 0; i <= userInfo.size(); i++) {
                                  String emailReturned = userInfo.get(i).getEmail();
                                  Log.d("response", "email returned: " + emailReturned);
                                  Log.d("sharedpref", "email: " + email);
                                  if (emailReturned.equals(email)) {
                                  Log.d("response:", "email match?: " + emailReturned.equals(email));
                                      flag = true;
                                      SharedPreferences.Editor editor = sharedPref.edit();
                                      editor.putInt("userID", userInfo.get(i).getId());
                                      Log.d("ID returned", String.valueOf(userInfo.get(i).getId()));
                                      editor.apply();
                                      break;
                                  }
                              }
                          }
                      } catch (Exception e) {
                          e.printStackTrace();
                      }
                  }
          
                  @Override
                  public void onFailure(Call<List<SavePlace>> call, Throwable throwable) {
                      Log.d("RESPONSE", "FAILED CHECKING USER ID/SOMETHING HAPPENED");
                  }
              });
              return flag;
          }
          
          }
          

          =&GT;相同的结果

          1. (等待你的建议)
          2. 提前感谢您的帮助。我希望这个问题,你的答案将有助于将来有同样问题的人

1 个答案:

答案 0 :(得分:0)

我解决了这个问题。我差不多2天都在寻找它!

使用pkill命令使用name spring终止所有进程,如下所示:

  $ pkill -15 -f spring

打开一个新终端并:        捆绑执行警卫 它给你错误“bundler:command not found:guard”别担心。请确保您已gem list bcrypt安装了bycrypt 安装捆绑包

sudo bundle install

然后重启服务器

sudo service apache2 restart
  

现在有效!