← Back to Upcase

My own show.html.erb


(Charlieanna) #1

Just looking the code of my show.html.erb please give me some advice.

<h1><%= @challenge.name %></h1>

  
<% if signed_in? %>
  <% if @team && !current_user.participating_in_challenge(@challenge)%>

    <%= link_to "Join Challenge", team_challenge_join_path(@team, @challenge),method: :post %>
  <% elsif !current_user.participating_in_challenge(@challenge) %>
    <%= link_to "Join Challenge", challenge_join_path(@challenge),method: :post %>
  <% end %>
<% end %>
<%= goal(@challenge) %>
<br>
<% if signed_in? %>
  <% if current_user.participating_in_challenge(@challenge) && @user_activity.in_progress? %>
    <%= link_to "Invite friends by creating a team.", new_challenge_team_path(@challenge) %>
    <%=  @user_activity.status %>
    <%= "You have covered #{@user_activity.steps_covered} steps so far since beginning of the challenge" %>
    <br>
    <% @daily_activities.each do |daily_activity| %>
   <%= daily_activity.start_time.day - 1 %>
    <%= form_for @daily_activity do |f| %>
      <%= f.label :steps_covered %>
      <%= f.number_field :steps_covered %>
      <%= f.submit "Add steps" %>
    <% end %>
   <% end %>
  <% end %>
<% end  %>
<% if @team_activity  %>
  <%= form_for @team_activity do |f|%>
    <%= f.label :start_time %><br />
    <%= f.text_field :start_time %>
    <%= f.submit "Start Challenge" %>
  <% end %>
<% end %>

<% if @user_activity && !@user_activity.start_time  %>
  <%= form_for @user_activity do |f|%>
    <%= f.label :start_time %><br />
    <%= f.text_field :start_time %>
    <%= f.submit "Start Challenge" %>
  <% end %>
<% end %>
<% if current_user.participating_in_challenge(@challenge) && @user_activity.in_progress? %>
  Challenge starts on <%= @user_activity.start_time %>
<% end %>

I know there might be partials, helpers but right now I am lost in how to start clearing this.

This is my controller method for that

def show
    @challenge = Challenge.find(params[:id])
    if params[:team_id]
      @team = Team.find(params[:team_id])
      @team_activity = TeamActivity.find_by(team:@team, challenge:@challenge)
    end

    if signed_in?
      @user_activity = UserActivity.find_by(user:current_user,challenge:@challenge)
      if @user_activity
        @daily_activities = @user_activity.daily_activities

        @daily_activities.each do |daily_activity|
          if daily_activity.start_time.day == Time.now.day
            @daily_activity = daily_activity
          end
        end
      end
    end
  end