John Munyi

Joined

4,360 Experience
27 Lessons Completed
0 Questions Solved

Activity

Posted in Implement a hash tags like feature in rails

Hi Chris looks like, https://github.com/ralovely/simple_hashtag is working brilliantly straight out of the box with now issues , happy to report

Posted in Implement a hash tags like feature in rails

Hi ,

I have looking for an actively supported gem to implement a hash tag like feature that can easily be used as a metric in feedback that has a lot of text. I checked-out

   https://github.com/ralovely/simple_hashtag 
   https://github.com/twitter/twitter-text-rb

and they both look out-dated ... any other out there , before i build one from scratch

Posted in Displaying previous score in current record

I think its the date , had totally missed your earlier comments

Posted in Displaying previous score in current record

we actually do have a previous record ... but it seems to only display the target set within this week only . We want to access the previous weeks record indeed

Posted in Displaying previous score in current record

with this :

   def last_score
       self.user.weekly_performance_reviews.order(week_start: :desc).last.kpi_quality_next_target
   end

we seen constrained to only 1 week, yet we want to compare the current weeks actual score vs the target that was set in the previous week , correct ?

Posted in Displaying previous score in current record

Let me try that right away

I actually don’t have a column for that day .. since its just for displaying purposes, but let me give it a shot

Posted in Displaying previous score in current record

I am using

   def week_of
         d = Date.today
         "Starting:"" ""#{d.beginning_of_week}"" ""Ending:"" ""#{d.beginning_of_week + 4}"
    end

to set a week ... whihc is covering Monday thro friday

Posted in Displaying previous score in current record

i tried using a class method:

   def last_score
       self.user.weekly_performance_reviews.last.kpi_quality_next_target
   end

But the previous score kept getting overwritten across all records

Posted in Displaying previous score in current record

Hi Chris,

Yes sought of .... so this is the use case. when we create a weekly_performance_review (this is done weekly) we have a target score which was set in the prev weeks review ... which is what we want to display during this weeks review on the new view, so that when we enter the actual score we can compare what we set last week vs what you have attained .

Posted in Displaying previous score in current record

Hi Chris I got a lil logic issue going on here, have a look at this gist

   https://gist.github.com/bl4ckdu5t/ec48cc9d6eedeb877d06

so technically what i want is for each new weekly_performance_review the target(has 3 fields) is equal to the last weeks next_target(has 3 fields also)

Appreciated

I have also factoting in this in the def new

    def new
       @weekly_performance_review = WeeklyPerformanceReview.new
      @users = User.all.map { |u| [u.name, u.id] }
  end

but it isnt helping much

Any fresh ideas

Posted in collapse-able form feature in nested forms

i got it working i had to tweek the above in to this

    <% @weekly_performance_review.coaching_forms.each_with_index do |coaching_form, index| %>
               <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
                 <div class="panel panel-default">
                   <div class="panel-heading" role="tab" id="headingOne">
                     <h4 class="panel-title">
                         <a role="button" data-toggle="collapse" data-parent="#accordion" href="#collapse<%= index.to_s %>" aria-expanded="true" aria-controls="collapseOne">
                        <h4> Coaching form dated <%= "#{coaching_form.date_of_session}" %></h4>
                       </a>
                    </h4>
                  </div>
                   <div id="collapse<%= index.to_s %>" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingOne">
                    <div class="panel-body">
                     <h4>coaching form goes here</h4>
                   </div>
                 </div>
               </div>
             </div>
           <% end %>

Posted in collapse-able form feature in nested forms

Hey Chris,

The Collapse / accordion js works but if you need to generate that in a loop then there is a problem, because the collapse use an ID which will not be unique in the case of the code below. id there a way we can pass or generate a unique id for each panel that is generated

  <div class="associated-forms">
          <h3>Associated coaching sessions</h3>
           <% @weekly_performance_review.coaching_forms.each do |coaching_form| %>
             <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
               <div class="panel panel-default">
                 <div class="panel-heading" role="tab" id="headingOne">
                   <h4 class="panel-title">
                     <a role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
                        <h4> Coaching form dated <%= "#{coaching_form.date_of_session}" %></h4>
                     </a>
                  </h4>
               </div>
              <div id="collapseOne" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingOne">
                  <div class="panel-body">
                  <h4>coaching form goes here</h4>
                </div>
              </div>
            </div>
          </div>
          <% end %>
      </div>

Posted in collapse-able form feature in nested forms

Hi Guys I am looking for a way to implement a collapsible feature within nested forms, such that during edit the existing forms dont open up in full and user decides which forms he / she wants to dive into using a collapsible panel to open the form in full size, is there an out of the box gem or way to implement that.

Posted in Rich text format editor in rails 4

Thanks Andrew and Chris .. Trix does it for me

Posted in Rich text format editor in rails 4

Thanks chris had tried out cke and its was a bit of an overkill in the wrong direction will checkout Trix... Need something simple

Posted in Rich text format editor in rails 4

I am looking for a rich text format editor that is compatible with rails 4, any good ones out there, I want to make beautiful text-areas with rich text.

cheers

Posted in Single sign in Devise STI

Hey there I have an STI on devise model which is working but there is an issue with how to manage what menus to show when different types of users are logged in here is my code

user.rb

    class User < ActiveRecord::Base

       #devise stuff here 
       has_many :attendances
        belongs_to :team

       self.inheritance_column = :type

        def self.types
        %w(Agent TeamLeader)
     end
 end

the sub classes

  class Agent < User

  end

  class TeamLeader< User

  end

sessioncontroller to allow single sign in

  class SessionsController < Devise::SessionsController
      def create
         rtn = super
         sign_in(resource.type.underscore, resource.type.constantize.send(:find, resource.id)) unless resource.type.nil?
          rtn
     end
 end

devise routes

   Rails.application.routes.draw do
      devise_for :users, :controllers => { :sessions => 'sessions' }
      devise_for :team_leaders, :skip => :sessions
     devise_for :agents, :skip => :sessions
  end

so if i try to pass a view with this code , <% elsif team_leader_signed_in? %> and <% elsif agent_signed_in? %> get totally ignored and the links are not displayed, what I am missing

       <% if user_signed_in? %>
          <li><%= link_to "Account", edit_user_registration_path %></li>
         <li><%= link_to "Log out", destroy_user_session_path, method: :delete %></li>
      <% elsif team_leader_signed_in? %>
          <li><%= link_to "I am Admin" %></li>
      <% elsif agent_signed_in? %>
         <li><%= link_to "I am Agent" %></li>
     <% else %>
         <li><%= link_to "Sign in",  new_user_session_path %></li>
         <li><%= link_to "Sign up",  new_user_registration_path %></li>
     <% end %>

So i made some progress and changed the above code to:

   <% elsif current_user.try(:admin?) %>
     <ul>
         <li><%= link_to "I am admin" %></li>
    </ul>
  <% else %>

now the "admin? is undefined" error is no more but still my method isnt being evaluate beacuse that link isnot visible even when A TeamLeader logs in to the App, why so ?

and if i run all these queries on the console they all return the correct value.

  User.find(5).type  #this return the correct type for the that user
  User.all #gives all users
  Agent.create(.......) #creates an agent successfully
  TeamLeader.create(.......) #works too

what i am missing in my user class method admin? that’s making it not be evaluated in :

               <% elsif current_user.try(:admin?) %>

because the only logical explanation is the code below is not being triggered or evaluated when .admin? is passed to the current_user..... or something like that

 def admin?
      type == "TeamLeader"
  end 

Posted in Using Pundit with ActiveAdmin

Hi I had similar challenges with sorcery and AA and finally made after i reached out to the AA guys , just raise an issue on the github repo he responds very fast and he will guide you in the right direction .... for all the troubles i had he responded with an hour or too a super helpful team they got.

All the best

Did something like this.

<% if current_user.admin? %>
.............
............
<% end %>

It throws admin method doesn't exist it's undefined