我正在尝试使用bcrypt来保护用户密码,但是当我在数据库中创建新用户时,我收到此错误:“LoadError:无法加载此类文件 - bcrypt”
到目前为止我做了什么:
我在Gemfile中放置了一个gem
sudo bundler install
我安装了它
$ gem list bcrypt
*** LOCAL GEMS ***
bcrypt (3.1.11)
bcrypt在宝石列表中
$ 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
sudo service apache2 restart
bcrypt-ruby
正如你所看到的那样无效!
我尝试再次卸载并安装bcrypt =&gt;相同的结果
我尝试过其他版本的bcrypt =&gt;相同的结果
install bcrypt --platform=ruby
添加到gems =&gt;相同的结果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;相同的结果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;相同的结果
提前感谢您的帮助。我希望这个问题,你的答案将有助于将来有同样问题的人
答案 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
现在有效!