Tag: 多态关联

Rails使用javascripting嵌套多态forms

我希望我的表格上有以下内容: 度是多态的部分,与profile的has_many关系。 这个部分由主要forms – 轮廓调用。 通过按“添加资格”,用户可以添加多个度数。 我已经能够只将一个学位附加到个人资料中,这是最后一个被忽略的人。 我甚至知道它为什么会发生,因为link_to无法传递配置文件实例。 所以我必须在degrees_controller中创建新的配置文件,你可以在我的代码中看到 。 提交“创建个人资料”时,最终个人资料实例是否可以选择上述所有其他个 请任何帮助,以便我可以将所有学位与表格相关联,我最后几天坚持使用SO和谷歌的所有排列和组合。 我已经准备好改变代码了……任何对此的帮助都将受到赞赏。

Rails 4 – 完成后评估模型 – 结构

我仍然对Rails有所了解。 我正在尝试为基于项目的app添加评估function。 我希望每个项目参与者在项目完成时提交评估。 我有一个评估模型: Evaluation.rb # == Schema Information # # Table name: evaluations # # id :integer not null, primary key # user_id :integer # evaluatable_id :integer # evaluatable_type :string # overall_score :integer # project_score :integer # personal_score :integer # remark :text # work_again? :boolean # continue_project? :boolean # created_at :datetime not null # […]

嵌套的simple_form,具有多态关联。 未经加工的参数

关于它的问题很多,但我找不到答案。 我有: group.rb class Group :describable accepts_nested_attributes_for :descriptions end description.rb class Description true end groups_controller.rb def update @group = Group.find(params[:id]) if @group.update_attributes(group_params) flash[:success] = “yes” redirect_to groups_path else render ‘edit’ end end private def group_params params.require(:group).permit(:owner_id, :domain, descriptions_attributes: [:id, :content]) end edit.html.erb 在控制台中我有Unpermitted parameter: description未创建Unpermitted parameter: description和嵌套属性。 我该怎么做才能最后保存?

polymorphic_path不生成正确的路径

我正在尝试使用名为polymorphic_path的rails方法,但我得到了错误的url。 我的多态关联是学生和房东,他们都是可用的用户。 这是我的模特: class User < ActiveRecord::Base belongs_to :userable, polymorphic: true end class Student :userable end class Landlord :userable end 我有一个名为current_user的变量,它包含User对象。 以下行: 给我url“users / 22”而不是返回学生/房东url。 这是我的routes.rb文件,如果这有帮助.. resources :users resources :students resources :landlords 我哪里错了? 谢谢!

Rails多态注释未定义方法user_name

所以我跟着Railscast 154关于实现多态关联,我能够启动并运行,但每当我尝试调用评论的用户时,我得到一个未定义的方法。 这是我的迁移: class CreateComments < ActiveRecord::Migration def change create_table :comments do |t| t.text :content t.belongs_to :commentable, polymorphic: true t.references :member t.timestamps end add_index :comments, [:commentable_id, :commentable_type] add_index :comments, :member_id end end CommentsController: class CommentsController < ApplicationController before_filter :authenticate_member! before_filter :load_commentable def create @comment = @commentable.comments.new(params[:comment]) if @comment.save redirect_to :back else render :new end end […]

Rails:Polymorphic User Table与AuthLogic一个好主意?

我有一个系统,我需要从主页上的一个登录表单登录三种用户类型:客户,公司和供应商。 我创建了一个User表,该表根据AuthLogic的示例应用程序工作, url为http://github.com/binarylogic/authlogic_example 。 我添加了一个名为“用户类型”的字段,该字段当前包含“客户”,“公司”或“供应商”。 注意:每个用户类型包含许多不同的字段,因此我不确定单表inheritance是否是最好的方法(如果此结论无效,则欢迎更正)。 这是一个多态关联,其中三种类型中的每一种都用用户记录“标记”了吗? 我的模型应该如何显示,以便我的用户表和我的用户类型客户,公司,供应商之间有正确的关系? 非常感谢! —— UPDATE —— 目前的设置: #User model class User true end #Customer model (Company and Vendor models are similar) class Customer :authenticable acts_as_authentic end 这是设置它们的有效方法吗?

Rails:如何创建多态关系/友谊模型

我想创建一个多态友谊/网络系统。 例如 用户可以请求或请求加入多个模型,例如: 公司 项目 组 联系人(朋友) 一些将是一对多,例如,一个公司雇用用户,但公司有许多雇员。 其他许多人,例如用户有许多项目,项目有很多用户 使用活动记录创建关系并不困难。 中间步骤,请求(邀请)让我感到困惑。 有点搞乱这是我想出来的。 下面的例子将允许我从一个配置文件(用户)向多个模型发出多边形的请求(甚至是一个单词?),包括配置文件模型本身。 这是Controller如何工作的示例。 @company = Company.find(params[:id]) @request = @company.requests.create!(status: “pending”).build_profile @request.profile = current_user 我怎样才能使@company更具动态性,比如说请求加入项目或个人资料(用户)的个人资料(用户)请求与另一个个人资料(用户)成为朋友? 所以我用控制器中的以下代码解决了这个小问题。 requests_controller.rb class RequestsController < ApplicationController before_filter :load_requestable def new @request = @requestable.requests.new end def create @request = @requestable.requests.new(params[:status]) if @request.save redirect_to @requestable, notice: "Request sent." else render :new end […]

如何在不同的命名空间下测试控制器以及为什么测试失败?

亲爱的花花公子, 我使用的是Rails 2.3,我创建了一个多态控制器,可以通过属于不同命名空间的Views访问。 这是故事,感谢您提前阅读: 我有这些路线: rake routes | grep appointment new_patient_appointments GET /patients/:patient_id/appointments/new(.:format) {:controller=>”appointments”, :action=>”new”} edit_patient_appointments GET /patients/:patient_id/appointments/edit(.:format) {:controller=>”appointments”, :action=>”edit”} patient_appointments GET /patients/:patient_id/appointments(.:format) {:controller=>”appointments”, :action=>”show”} PUT /patients/:patient_id/appointments(.:format) {:controller=>”appointments”, :action=>”update”} DELETE /patients/:patient_id/appointments(.:format) {:controller=>”appointments”, :action=>”destroy”} POST /patients/:patient_id/appointments(.:format) {:controller=>”appointments”, :action=>”create”} new_admin_doctor_appointments GET /admin/doctors/:doctor_id/appointments/new(.:format) {:controller=>”admin/appointments”, :action=>”new”} edit_admin_doctor_appointments GET /admin/doctors/:doctor_id/appointments/edit(.:format){:controller=>”admin/appointments”, :action=>”edit”} admin_doctor_appointments GET /admin/doctors/:doctor_id/appointments(.:format) {:controller=>”admin/appointments”, :action=>”show”} PUT /admin/doctors/:doctor_id/appointments(.:format) {:controller=>”admin/appointments”, :action=>”update”} […]

RESTful破坏Rails中的多态关联?

我如何破坏关联本身并让对象单独关联,同时保持这个RESTful? 具体来说,我有这些模型: class Event :surveyable, :dependent => :destroy, :include => :survey has_many :surveys, :through => :model_surveys end class ModelSurvey true end class Survey < ActiveRecord::Base has_many :model_surveys end 这就是说事件是:surveyable ( ModelSurvey belongs_to Event )。 我的问题是,无需创建ModelSurveysController ,如何在ModelSurvey保留Event和Survey同时销毁ModelSurvey ? map.resources :events, :has_many => :model_surveys ? 我不太确定在这种情况下该怎么做。 路由需要发生什么,控制器需要发生什么? 我希望url看起来像这样: /events/:title/model_surveys/:id 谢谢你的帮助,兰斯

如何在Rails 2.3中测试多态控制器?

亲爱的花花公子, 我会尽力说明问题的实质。 提前感谢您的耐心等待。 My Polymorphic Controller( Appointments )由两个Views ,第一个属于Admin::Doctor命名空间,第二个属于Patient命名空间。 routes.rb的相关部分: map.resources :patient do |patients| patients.resources :appointments end map.namespace(:admin) do |admin| admin.resources :doctor do |doctors| doctors.resources :appointments end end 所以,我现在可以得到: patients/:patient_id/appointments admin/doctors/:doctor_id/appointments ……和实际路线: rake routes | grep appointment new_patient_appointments GET /patients/:patient_id/appointments/new(.:format) {:controller=>”appointments”, :action=>”new”} edit_patient_appointments GET /patients/:patient_id/appointments/edit(.:format) {:controller=>”appointments”, :action=>”edit”} patient_appointments GET /patients/:patient_id/appointments(.:format) {:controller=>”appointments”, :action=>”show”} PUT /patients/:patient_id/appointments(.:format) {:controller=>”appointments”, […]