Adrien Nhem

Joined

1,690 Experience
15 Lessons Completed
0 Questions Solved

Activity

Posted in API HTTP Requests using Faraday Discussion

I'm currently going through the video and as of faraday 2.0, the faraday_middleware gem has been deprecated and most adapters have been bundled into the faraday gem. More details here: https://github.com/lostisland/faraday/blob/main/UPGRADING.md

Posted in Using Webhooks with Stripe Discussion

Hi,

Are you sure that the endpoint in stripe contains /webhooks/stripe at the end of the URL?

This fixed it for me.

Posted in How do I validates uniqueness of parent of parent?

Hi guys!

I have 3 models: lectures > chapters > lessons

With a has_many through relationship.

The problem: each lecture should have a lesson with the same step for ordering.

In lesson.rb I'm trying to:

validates :step, uniqueness: { scope: :lecture_id }

In the console it seems that lecture_id is nil.

Sorry if the explanation is messy!

Thank you Chris for your reply. But I can't make it work.

I made sure that I was using Turbolinks 3.

The dashboard that I am building only use get request that links to a show method on different controllers.

The controller that handles the redirection to the different partials from the different action of the different controllers is profiles_controller.rb. The layout includes a permanent sidebar menu.

What I have tried to do

  1. And the div that is always updated is #dashboard to which I have added data-turbolinks-temporary as it is supposed to be modified.
  2. Added remote: true to the link_to
  3. In the lectures controller I have added render partial: "show", change: 'dashboard' So that it is supposed to replace all the elements within the div ided dashboard.
  4. Added Turbolinks.visit(url, { change: ['dashboard'] })

Did I actually missed something because when I click on the link_to, the partial is rendered but the url is not updated and if then I hit refresh or back button it redirects me to the very first page instead of reloading the same partial? Maybe I am trying to do something different? Or just lost ^

Thanks for your time!

Hi guys!

I have been asking this question everywhere... basically I am building a user dashboard and it load the main div with ajax calls. I wanted to know how can I update the URL when an ajax call is made so that I can refresh the page with the same ajax partial and then use the back button as well? Any idea is more than welcome. I have very basic knowledge about javascript.

I am using turbolinks, ruby on rails 4.

Many thanks!

I kicked myself! haha

Actually I have found the answer, I must have been really tired....

What I did is that I just added to the lessons_controller.rb seems to do the trick actually. Will run some test.

  def show
    @lecture = Lecture.find(params[:lecture_id])
    @lesson = @lecture.lessons.find(params[:id])
    **authorize @lecture**
  end

working with pundit gem. Is it possible to apply the same rule to nested resources? if show is not allowed in lecture_policy then show in lesson_policy should not be allowed too.

Lecture
    has_many :enrollments
    has_many :users, through: :enrollments
   has_many :lessons
end

Lesson
    belongs_to :lecture
end

User
   has_many :lectures, through: enrollments
   has_many :enrollments
end

Enrollment
    belongs_to :user
    belongs_to :lecture
end

LecturePolicy

class LecturePolicy < ApplicationPolicy
    def index?
        true
    end

    def create?
        false
    end

    def update?
        false
    end

    def edit?
        false
    end

     class Scope < Scope
        def resolve
            scope.where(:id => user.enrollments.select(:lecture_id))
        end
      end

end

Thanks so much for your comments!