我的Rails 4应用程序出现问题。
我正在尝试按照本教程https://coderwall.com/p/rqjjca/creating-a-scoped-invitation-system-for-rails进行一些修改。
本教程跳过了作者认为过于容易打扰的几个步骤 - 我认为这就是我被卡住的地方。
我有个人资料,项目,团队和用户的模型。
协会是:
Profile.rb
has_many :teams, foreign_key: "team_mate_id"
has_many :team_projects, through: :teams, source: :project
has_many :invitations, :class_name => "Invite", :foreign_key => 'recipient_id'
has_many :sent_invites, :class_name => "Invite", :foreign_key => 'sender_id'
Project.rb
belongs_to :profile
has_one :team
has_many :team_mates, through: :team
has_many :invites
Team.rb
belongs_to :project
belongs_to :team_mate, class_name: "Profile"
Invite.rb
belongs_to :project
belongs_to :sender, :class_name => 'Profile'
belongs_to :recipient, :class_name => 'Profile'
在我的路线中,我有:
resources :invites
resources :teams
resources :profiles, only: [:show, :edit, :update, :destroy]
resources :projects do
member do
put "invite_team_mates" => "projects/invite_team_mates", as: :invitation
end
在我的项目视图文件夹中,我有部分邀请表格:
<%= form_for @invite , :url => invites_path do |f| %>
<%= f.hidden_field :project_id, :value => @invite.project_id %>
<%= f.label :email %>
<%= f.email_field :email %>
<%= f.submit 'Send' %>
<% end %>
我还尝试将此作为项目视图文件夹中名为invite_team_mates.html.erb的常规文件,并在项目控制器中对其进行了匹配操作,该操作具有以下操作:(具有上面针对该特定的路由行动)。
def invite_team_mate
project = Project.find(params[:id])
authorize @project
end
我也不确定是否必须更改form_for @invite的开头行应该与@project.invite有关。我不确定。
我还有一个邀请控制器:
class InvitesController < ApplicationController
def new
@invite = Invite.new
end
def create
@invite = Invite.new(invite_params)
@invite.sender_id = current_user.profile.id
if @invite.save
#if the user already exists
if @invite.recipient != nil
#send existing user email invitation to join project team
InviteMailer.existing_user_invite(@invite).deliver
#Add the user to the user group - inivte rsvp pending
@invite.recipient.project.push(@invite.project)
else
#send new user email invitation to join as a general user as well as join this project team
InviteMailer.new_user_invite(@invite, new_user_registration_path(:invite_token => @invite.token)).deliver
end
else
# oh no, creating an new invitation failed
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_invite
@invite = Invite.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def invite_params
params[:invite].permit(:email)
end
end
我真的被困在如何把所有这些挂在一起。
我的目标是允许创建项目的用户邀请其他人加入项目团队。我对此并没有走得太远。当我尝试保存所有这些并打开项目时,我收到一条错误消息:
First argument in form cannot contain nil or be empty
错误突出显示部分邀请形式的部分:
<%= form_for @invite , :url => invites_path do |f| %>
当我尝试更改此行以使用简单的表单语法时,如下所示:
<%= simple_form_for(@invite, :url => invites_path) do |f| %>
我收到错误消息:
undefined method `model_name' for nil:NilClass
我认为这可能与@invite保存在projects视图文件夹中的表单有关。
有人能看出出了什么问题吗?
更新 - 终端线
NoMethodError - undefined method `model_name' for nil:NilClass:
actionpack (4.2.4) lib/action_controller/model_naming.rb:9:in `model_name_from_record_or_class'
actionview (4.2.4) lib/action_view/record_identifier.rb:47:in `dom_class'
simple_form (3.2.0) lib/simple_form/action_view_extensions/form_helper.rb:62:in `simple_form_css_class'
simple_form (3.2.0) lib/simple_form/action_view_extensions/form_helper.rb:22:in `simple_form_for'
app/views/projects/_invite_team_mate.html.erb:6:in `_app_views_projects__invite_team_mate_html_erb___1258064784578419157_70357207009700'
actionview (4.2.4) lib/action_view/template.rb:145:in `block in render'
activesupport (4.2.4) lib/active_support/notifications.rb:166:in `instrument'
actionview (4.2.4) lib/action_view/template.rb:333:in `instrument'
actionview (4.2.4) lib/action_view/template.rb:143:in `render'
actionview (4.2.4) lib/action_view/renderer/partial_renderer.rb:339:in `render_partial'
actionview (4.2.4) lib/action_view/renderer/partial_renderer.rb:310:in `block in render'
actionview (4.2.4) lib/action_view/renderer/abstract_renderer.rb:39:in `block in instrument'
activesupport (4.2.4) lib/active_support/notifications.rb:164:in `block in instrument'
activesupport (4.2.4) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.2.4) lib/active_support/notifications.rb:164:in `instrument'
actionview (4.2.4) lib/action_view/renderer/abstract_renderer.rb:39:in `instrument'
actionview (4.2.4) lib/action_view/renderer/partial_renderer.rb:309:in `render'
actionview (4.2.4) lib/action_view/renderer/renderer.rb:47:in `render_partial'
actionview (4.2.4) lib/action_view/renderer/renderer.rb:21:in `render'
actionview (4.2.4) lib/action_view/helpers/rendering_helper.rb:32:in `render'
haml (4.0.7) lib/haml/helpers/action_view_mods.rb:12:in `render_with_haml'
app/views/projects/show.html.erb:976:in `_app_views_projects_show_html_erb__3676206074319755518_70357179499400'
actionview (4.2.4) lib/action_view/template.rb:145:in `block in render'
activesupport (4.2.4) lib/active_support/notifications.rb:166:in `instrument'
actionview (4.2.4) lib/action_view/template.rb:333:in `instrument'
actionview (4.2.4) lib/action_view/template.rb:143:in `render'
actionview (4.2.4) lib/action_view/renderer/template_renderer.rb:54:in `block (2 levels) in render_template'
actionview (4.2.4) lib/action_view/renderer/abstract_renderer.rb:39:in `block in instrument'
activesupport (4.2.4) lib/active_support/notifications.rb:164:in `block in instrument'
activesupport (4.2.4) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.2.4) lib/active_support/notifications.rb:164:in `instrument'
actionview (4.2.4) lib/action_view/renderer/abstract_renderer.rb:39:in `instrument'
actionview (4.2.4) lib/action_view/renderer/template_renderer.rb:53:in `block in render_template'
actionview (4.2.4) lib/action_view/renderer/template_renderer.rb:61:in `render_with_layout'
actionview (4.2.4) lib/action_view/renderer/template_renderer.rb:52:in `render_template'
actionview (4.2.4) lib/action_view/renderer/template_renderer.rb:14:in `render'
actionview (4.2.4) lib/action_view/renderer/renderer.rb:42:in `render_template'
actionview (4.2.4) lib/action_view/renderer/renderer.rb:23:in `render'
actionview (4.2.4) lib/action_view/rendering.rb:100:in `_render_template'
actionpack (4.2.4) lib/action_controller/metal/streaming.rb:217:in `_render_template'
actionview (4.2.4) lib/action_view/rendering.rb:83:in `render_to_body'
actionpack (4.2.4) lib/action_controller/metal/rendering.rb:32:in `render_to_body'
actionpack (4.2.4) lib/action_controller/metal/renderers.rb:37:in `render_to_body'
这些界线一直在继续 - 我不确定这是否是'backtrace'的意思