Tag: cocoon gem

Javascript:在javascript代码中使用模型中的方法

我正在尝试在资产上设置用户,我max_users的问题是不确定如何将我的max_users方法从asset.rb给我的JS代码。 我试图使用带有Cocoon gem的max_users方法让“Add Another”按钮在达到该资产允许的指定max_users时消失。 硬件将始终设置为max_user为1,而软件永远不会有max_user值。 Max_users和profile_type一样工作。 JS工作原样,但不是总是停在1,我需要让它在max_users中注册值,并将show / hide作为基础。 任何帮助都感激不尽。 并提前谢谢你。 JS: $ -> check_to_hide_add_link = -> if $(“#assets_users .nested-fields”).length is 1 $(“#assets_users .links a”).hide() else $(“#assets_users .links a”).show() $(“#assets_users”).bind “cocoon:after-insert”, -> check_to_hide_add_link() $(“#assets_users”).bind “cocoon:after-remove”, -> check_to_hide_add_link() check_to_hide_add_link() Asset.show: – if @asset.users.empty? = simple_form_for([@asset_profile, @asset]) do |f| = f.input :max_users, as: :hidden #assets_users = f.simple_fields_for […]

使用uniq id进行部分渲染

我试图在用户按下按钮时渲染部分视图,所以实际上它是部分列表(相同部分呈现的次数更多)我使用cocoon gem来渲染部分像这样: “radius blue button” %> 在我的部分我有这个代码: 所以我的想法是为每个渲染的部分都有一个uniq id,但我的问题是部分渲染确定但是id是相同的,生成的第一个id应用于每个部分

Cocoon Gem:未定义的方法`new_record?’ for nil:link_to_remove_association上的NilClass

我正在尝试使用Cocoon Gem构建嵌套表单。 但是我得到的错误如下所示。 我发现Rails Cocoon Gem:Undefined Method’new_record? 在与Wicked的link_to_remove_association上 。 但是,从我的模型代码中可以看出,唯一的答案已被排除。 错误 ActionView::Template::Error (undefined method `new_record?’ for nil:NilClass): 1: 2: 3: 4: app/views/templates/_room_fields.html.erb:3:in `_app_views_templates__room_fields_html_erb__1867913568926009508_70125979350780′ app/views/templates/_form.html.erb:5:in `block (2 levels) in _app_views_templates__form_html_erb__4123974558704004784_70125994949300′ app/views/templates/_form.html.erb:4:in `block in _app_views_templates__form_html_erb__4123974558704004784_70125994949300′ app/views/templates/_form.html.erb:1:in `_app_views_templates__form_html_erb__4123974558704004784_70125994949300′ app/views/templates/new.html.erb:1:in `_app_views_templates_new_html_erb___3689493092838604682_70125964273280’Models 楷模 class Template true end class Room true end class Item < ActiveRecord::Base belongs_to :room end 表单视图 room […]

Rails materialize-sass表单,带有自动完成和cocoon gem嵌套资源

我在表单上使用materialize-sass gem。 使用自动完成function获取供应商名称。 表单上的其他字段是项目名称和数量,它们是嵌套资源。 为此,我使用茧gem 出于某种原因,页面第一次加载,似乎一切正常。 但添加更多字段似乎不起作用。 我尝试使用下拉选择,但不显示项目列表。 我用另一个自动完成替换它,主要字段显示但是自动完成function不起作用。 知道什么可能是错的吗? 请参阅下面的代码。 purchase_orders _forms.html.erb Item List purchase_order_detail %> _purchase_order_detail_fields.html.erb “material-icons teal-text text-lighten-1” %> params[:category_id] %>

Rails cocoon-gem双嵌套表单“未定义方法”

我在我的rails应用程序中使用cocoon gem并试图双重嵌套表单。 第一个“link_to_add_association”添加了valve_fields partial,其中包含另一个“link_to_add_association”,它给出了这个错误: ActionView::Template::Error (undefined method `fetch_value’ for nil:NilClass): 21: .line_items 22: =f.simple_fields_for :line_items do |line_item| 23: =render ‘line_item_fields’, :f => line_item 24: //error line// =link_to_add_association “add line”, f, :line_items 我没有为第一个链接做任何不同的事情而不是第二个链接,但由于某种原因它不起作用 //Rfq controller def rfq_params params.require(:rfq).permit( :quote_number,:rep_id, :owner, :customer_id, :customer_name, :end_user_list, :application_list, :due, :ship_date, :is_budgetary, :notes, :mandatory_due_date, valves_attributes: [:id, :_destroy, :productline, :discwedge, :valvetype, :valveends, […]

Rails3 Cocoonvalidation嵌套字段计数

我遇到了使用cocoon进行validation的问题以及允许使用模型的字段数。 使用cocoon,rails3,我有一个嵌套的表单,我的位置有很多链接。 我需要限制每个位置的链接数量为5。 在我的location.rb模型中,我有这个: class Location lambda { |a| a[:link_name].blank? }, :allow_destroy => true validate :check_link_count … def check_link_count if self.links.count > 5 self.errors.add :base, “No more than 5 links allowed.” end end … 最多可添加5个链接,一切正常。 如果我添加6个链接并保存,我会收到错误消息。 也不错。 问题是当我尝试删除链接时 – 看起来链接只在保存后被删除(我认为)。 因此,如果我删除所有字段,我仍然会收到错误。 有什么建议? 还有其他方法可以validation吗?

Rails 4 – 带有Cocoon gem的嵌套属性

我正在尝试用Rails 4创建一个应用程序。 我正在使用Cocoon gem来创建具有简单forms的嵌套表单。 我有一个资格模型,嵌套在一个配置文件模型中。 协会是: 资格 belongs_to :profile 轮廓 has_many :qualifications accepts_nested_attributes_for :qualifications, reject_if: :all_blank, allow_destroy: true 在我的个人资料表格中,我将资格属性与以下内容相结合: 在我的资格表格属性中,我有: “Your award” %> “Are you currently studying toward this qualification?” %> “When did you graduate?”, collection: (Date.today.year – 50)..(Date.today.year + 5) %> 在我的配置文件控制器中我有: def new @profile = Profile.new @profile.qualifications_build @profile.build_vision @profile.build_personality @profile.addresses_build authorize @profile end […]

邪恶的gem与茧gem和设计用户模型

所以我有一个User devise生成的User模型,我正在使用Wicked gem为我提供多forms选项,从用户那里获取更多数据并将其存储在用户模型中。 一切都工作正常,但知道我正在尝试添加另一个用户有很多学位的模型。 我正在使用cocoon gem让我增加额外的degrees 。 我可以进入多forms页面并输入学位信息,甚至可以向用户添加更多学位,但是当我提交表单时,我收到错误; param is missing or the value is empty: user 其他所有其他内容实际上都得到了保存,我可以查看用户和输入的其余字段但不是度数。 用户模型: has_many :degrees accepts_nested_attributes_for :degrees, reject_if: :all_blank, allow_destroy: true 学位模型: belongs_to :user user_steps_controller(这是邪恶的gem控制器): class UserStepsController < ApplicationController include Wicked::Wizard steps :personal, :avatar_and_about_yourself, :social, :education def show @user = current_user render_wizard end def update @user = current_user @user.update_attributes(user_params) […]

Ruby on Rails:Selectize.js与Cocoon

我正在尝试在Ruby on Rails中创建一个表单来选择构造的一部分。 新的字段(部分条目 – 连接表)由Cocoon gem添加。 一切正常,但在尝试编辑保存的结构时,Selectize无法读取其当前部分的字段。 这是我的_part_fields.html.erb: “Select or create a part…”}, {class => “construction_part_select”} %> application.js中: //= require jquery //= require jquery.turbolinks //= require jquery_ujs //= require selectize //= require bootstrap //= require bootstrap-sprockets //= require cocoon //= require_tree . jQuery(function () { console.log(“jQuery”); $(“#construction_part_select”).each(function () { console.log(“iter1”); $(this).selectize({ create: true, sortField: […]

Rails – Cocoon gem – 嵌套表格

我正在尝试用Rails 4创建一个应用程序。 我为表单使用简单的表单gem,并尝试使用Cocoon gem作为表单的嵌套元素。 我问了这个问题,它解释了我想要更详细地实现的内容: Rails – 单个属性的多个条目 我有个人资料模型和资格模型。 协会是: profile.rb has_many :qualifications accepts_nested_attributes_for :qualifications, reject_if: :all_blank, allow_destroy: true qualification.rb belongs_to :profile 配置文件控制器包含强参数中的限定属性: def profile_params params[:profile].permit(:user_id, :title, :hero, :overview, :research_interest, :occupation, :external_profile, :working_languages, :tag_list, qualifications_attributes: [:id, :level, :title, :year_earned, :institution, :_destroy] ) end 我的个人资料表现在有: Your qualifications 我的资格部分表单现在在我的资格视图文件夹中命名为_qualifications_fields.html.erb “Your award” %> “When did you graduate?”, collection: […]