【问题标题】:How do I fix this error: Permission denied - /Library/Ruby/Gems/2.0.0/gems/city-state-0.0.13/lib/db/states.us如何解决此错误:权限被拒绝 - /Library/Ruby/Gems/2.0.0/gems/city-state-0.0.13/lib/db/states.us
【发布时间】:2016-11-06 22:28:26
【问题描述】:

目前,我正在开发一个关于 Ruby on Rails 的客户项目,该项目要求提供用户名、名字、姓氏、街道 1、街道 2、城市和州等信息。在这个项目中,City 和 State 应该是选择框,其中包含来自 city-state gem 的填充条目。

我在 Gemfile 中输入 gem 'city-state',然后在终端 (Mac OS) 中运行 bundle install

现在在我的表单文件中,_form.html.erb:

<%= form_for(@customer) do |f| %>
    <% if @customer.errors.any? %>
        <div id="error_explanation">
          <h2><%= pluralize(@customer.errors.count, "error") %> prohibited this customer from being saved:</h2>

          <ul>
            <% @customer.errors.full_messages.each do |message| %>
                <li><%= message %></li>
            <% end %>
          </ul>
        </div>
    <% end %>

    <div class="field">
      <%= f.label :username %><br>
      <%= f.text_field :username %>
    </div>
    <div class="field">
      <%= f.label :first_name %><br>
      <%= f.text_field :first_name %>
    </div>
    <div class="field">
      <%= f.label :last_name %><br>
      <%= f.text_field :last_name %>
    </div>
    <div class="field">
      <%= f.label :street1 %><br>
      <%= f.text_field :street1 %>
    </div>
    <div class="field">
      <%= f.label :street2 %><br>
      <%= f.text_field :street2 %>
    </div>
    <div class="field">
      <%= f.label :state %><br>
      <select id="states-of-country" name="state">
        <option value="" selected="">Select Your State</option>
        <% CS.states(:us).each do |key, value| %>
        <option value="&lt;%= key %&gt;"><%= value %></option>
        <% end %>
      </select>
    </div>
    <div class="field">
      <%= f.label :city %><br>
      <select id="cities-of-state" name="city">
        <option value="" selected="">Select Your City</option>
      </select>
    </div>

    <script>
        $('#states-of-country').change(function () {
            var input_state = $(this);
            var cities_of_state = $("#cities-of-state");

            if ($(this).val() == "") {
                cities_of_state.html("");

            } else {
                $.getJSON('/cities/' + $(this).val(), function (data {
// cities_of_state.empty();
                    var opt = '<option value="" selected="">Select Your City</option>';
                    console.log(data);
                    if (data.length == 0) {

                    } else {
                        data.forEach(function (i) {
                            opt += '<option value="+ i +">' + i + '</option>';
                            cities_of_state.html(opt);
                        });
                    }
                });
            }
        });
    </script>
    <div class="actions">
      <%= f.submit %>
    </div>
<% end %>

错误集中在CS.states(:us) 然后当我运行服务器时,每次我去创建或编辑客户时,我都会收到这个错误:

权限被拒绝 - /Library/Ruby/Gems/2.0.0/gems/city-state-0.0.13/lib/db/states.us

PS。在我的 gem 文件中输入 gem 'city-state' 之前,我首先在终端中执行此操作:sudo gem install 'city-state'

【问题讨论】:

  • 尝试使用 gem install 'city-state' 运行。然后重试看看是否有效。
  • 你应该使用sudo 命令来安装你的gem,除非绝对必要
  • 这正是我最初所做的。我已经安装了城邦,但我不断收到 Errno::EACCES 错误。 @ore​​oluwa
  • 好的。不过,一个建议是,始终使用版本管理器,例如 rbenvrvm 来管理您的 ruby​​ 版本。将为您节省大量的生产时间
  • 我已经通过输入“sudo chown -R $(whoami) /Library”解决了这个问题:)

标签: ruby-on-rails ruby macos rubygems


【解决方案1】:

这是因为系统 ruby​​ 和 gem 中的文件权限是以 root 身份安装的。快速修复是chmod/chown/Library/Ruby/Gems/2.0.0/gems/

但更好的方法是使用像 rbenvrvm 这样的 ruby​​ 版本管理器,这样您就可以单独安装 ruby​​。 RVM 甚至提供了“gemset”功能 - 这样您就可以为每个项目提供独立的 gem 环境。

【讨论】:

    【解决方案2】:

    我有同样的问题,这个解决方案对我有用:

    $gem 哪个城邦

    -> /Users/macbook/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/city-state-0.0.13/lib/city-state.rb

    $sudo chown -R $(whoami) /Users/macbook/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/*

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-07-14
      • 1970-01-01
      • 2014-10-19
      • 1970-01-01
      • 2022-01-15
      • 1970-01-01
      • 2019-01-10
      • 1970-01-01
      相关资源
      最近更新 更多