Right now, I am currently working on a Customer project on Ruby on Rails that asks for information such as Username, First Name, Last Name, Street 1, Street 2, City and State. In this project, the City and State should be select boxes with populated entries from the city-state gem.
I typed gem 'city-state' in my gem file then run "bundle install" in the terminal (Mac OS).
Now in my form file, _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="<%= key %>"><%= 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 %>
The error focuses on the "CS.states(:us)" then when I run the server, everytime I go to the create or edit customer, i receive this error: "Permission denied - /Library/Ruby/Gems/2.0.0/gems/city-state-0.0.13/lib/db/states.us"
PS. Before I typed "gem 'city-state'" in my gem file, I did this first in the terminal: "sudo gem install 'city-state'"
Aucun commentaire:
Enregistrer un commentaire