所以我有一个应用程序,有点像meetup.com,用户可以创建事件,评论事件,通过GPS半径搜索事件。但是,我想让用户点击'参加'按钮,然后在events / show.html.erb页面上显示哪些用户正在参加...
我该怎么做?
当前事件show.html.erb
<%= render 'shared/header' %>
<div class="container">
<div class="row">
<div class="span3">
<%= render 'sidebar' %>
</div>
<div class="span5">
<div class="new_event_form">
<div class="line1"><h4>Create event</h4></div>
<%= form_for current_user.events.new, remote: true do |f| %>
<h5>Event title:</h5>
<div><%= f.text_field :title, placeholder: "Event title", required: true, autocomplete: :off %></div>
<h5>Event description:</h5>
<div><%= f.text_area :description, placeholder: "Event description", required: true, autocomplete: :off %></div>
<h5>Event date:</h5>
<div><%= f.text_field :date %></div>
<h5>Event location:</h5>
<div><%= f.text_field :location, placeholder: "Event location", required: true, autocomplete: :off %></div>
<div>
<%= f.submit "Create event", class: 'btn btn-primary' %>
<%= link_to "Cancel", '#', class: 'btn cancel_event' %>
</div><br />
<% end %>
</div>
<div class="events_list">
<!-- look in events/event.hmlt.erb -->
<h4><%= @event.title %> at <%= @event.location %></h4>
<p><%= @event.description %></p>
<h5><i class="fa fa-calendar-o"></i> <%= @event.date.strftime("%A, %B %d, %Y") %></h5>
<h5><i class="fa fa-clock-o"></i> <%= @event.time %></h5>
<h5><i class="fa fa-map-marker"></i> <%= @event.location %></h5>
</div>
<div class="name"></div>
<%= form_for [@commentable, @comment], remote: true do |f| %>
...........and so on...
先谢谢!
答案 0 :(得分:2)
您需要在routes.rb和事件控制器中定义“出席”操作,然后为其创建attend.html.erb表单。
编辑:在routes.rb
中 resources :events do
post 'attend', on: :member
end
在events_controller中
def attend
@event.attendees << current_user
@event.save
end
show.html.erb中的
<%= button_to 'Attend', attend_event_path(@event), method: :post, confirm: 'really?' %>
并制作一个很好的attend.html.erb来表示“感谢您注册”