Sonny Black
Sonny Black

Reputation: 1617

How to let users attend events?

So I have an app, sort of like meetup.com, users can create events, comment on the events, search the events by GPS radius.. However, I'd like to allow users to click on an 'Attend' button and then on the events/show.html.erb page show which users are attending etc...

How might I do this?

current event 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...

Thanks in advanced!

Upvotes: 0

Views: 966

Answers (1)

DeeY
DeeY

Reputation: 962

You need to define 'attend' action in your routes.rb and your Event controller, and then create attend.html.erb form for it.

Edit: in routes.rb

 resources :events do
   post 'attend', on: :member
 end

in events_controller

def attend
  @event.attendees << current_user
  @event.save
end

in show.html.erb somewhere

 <%= button_to 'Attend', attend_event_path(@event), method: :post, confirm: 'really?' %>

and make a nice attend.html.erb to say "thanks for signing up"

Upvotes: 2

Related Questions