上下文:对于用于自行车租赁的 Ruby on Rails 应用程序,我使用 gem globalize 来处理:description不同语言的输入。
当前状态: globalize 实现有效,这取决于我能够以description特定语言存储的语言环境。输入 for:description是根据整个网页的区域设置处理的。
这意味着此页面上的所有内容都必须更改语言才能以:description正确的语言存储。
或者,我也可以显示所有可用的语言环境并description为每个语言环境显示。(另请参阅下面注释掉的代码)。
问:我正在寻找一种方法,让用户只选择一种语言:description,然后:description以正确的语言保存,而无需更改整个网页的语言。
代码
形式
<div class="row">
<%# I18n.available_locales.each do |locale| %>
<!-- <h1><%#= locale %></h1> -->
<%= f.globalize_fields_for locale do |ff| %>
<div class="col-10">
<div class="form-group">
<label class="form-control-label text required" for="accommodation_category_description">Description</label>
<div><%= ff.text_area :description, :rows =>"5", :cols =>"30", class:"form-control is-valid text required" %></div>
</div>
</div>
<% end %>
<%# end %> …Run Code Online (Sandbox Code Playgroud) 在我的 Ruby on Rails 应用程序中,自行车租赁公司可以管理他们的所有自行车(预订、付款等)。
背景
我想为自行车租赁公司 ( shops) 提供在自己的网站上实施预订表格的选项,这样他们就可以让客户预订bike.
bike_categories在给定日期bikes可以预订的航班。arrivaldeparture问题
为了管理这个问题,我想生成一个 API 控制器操作,显示 某个availability特定的可用数量。 bike_categorycountbikesbike_category
根据这篇文章
我应该能够处理 api 中的查询,但是如何在 Rails 控制器中获取查询?
代码
楷模
class Shop < ApplicationRecord
has_many :bike_categories, dependent: :destroy
has_many :bikes, through: :bike_categories
has_many :reservations, dependent: :destroy
end
class Reservation < ApplicationRecord
belongs_to :shop
belongs_to :bike
end
class Bike < ApplicationRecord
belongs_to :bike_category
has_many :reservations, dependent: :destroy
end …Run Code Online (Sandbox Code Playgroud)