我的Rails 4应用程序中有模型用于项目和兴趣。协会是:
项目
has_many :interests
兴趣
belongs_to :project
belongs to: user
兴趣表格的目的是让用户注册对项目的兴趣。
在我的项目展示视图中,我有两个注册兴趣的链接。用户可以作为参与者或观察者表达对项目的兴趣。
在我感兴趣的形式中,我有两个布尔字段,名为:participant和:observer。
我试图弄清楚如何使用' true'来填充相关的布尔属性,具体取决于用户点击进入表单的链接。如果他们点击“参与此项目'”,则兴趣表中的参与者属性应设置为true。
以我的兴趣形式,我有:
<%= f.hidden_field :user_id, @current_user.id %>
<%= f.hidden_field :project_id, @project.id %>
<%= f.input :observe, as: :radio_buttons, :label => "Do you want to monitor this project?" %>
<%= f.input :participate, as: :radio_buttons, :label => "Do you want to participate in this project?" %>
根据项目显示的用户访问此表单的链接,我是否可以通过这种形式自动完成观察并参与布尔值?
感兴趣的路线(在我的应用中实际上被称为&#39; eoi&#39;
rake routes | grep eoi
eois GET /eois(.:format) eois#index
POST /eois(.:format) eois#create
new_eoi GET /eois/new(.:format) eois#new
edit_eoi GET /eois/:id/edit(.:format) eois#edit
eoi GET /eois/:id(.:format) eois#show
PATCH /eois/:id(.:format) eois#update
PUT /eois/:id(.:format) eois#update
DELETE /eois/:id(.:format) eois#destroy
在项目展示视图中,我有这些链接来注册参与或监控项目的兴趣:
<%= link_to 'Participate', new_eoi_path(@eoi) %>
<%= link_to 'Monitor', new_eoi_path(@eoi) %>