1,230 Experience
9 Lessons Completed
0 Questions Solved


Posted in jQuery.ajax url: rails

In my code I have this button

<button class="btn btn-success btn-lg" id="check_module">Pay</button>

In my code I have this button

Expand snippet
when clicked on iframe opens from this javascript code

<script type="text/javascript" src=""></script>
<script type="text/javascript" src=""></script>

<%= javascript_tag do %>
  $("#check_module").click(function () {
    IMP.init(''); //iamport 대신 자신의 "가맹점 식별코드"를 사용하시면 됩니다
      merchant_uid : "<%= @merchant_uid %>",
      name : '결제테스트',
      amount : <%= @price %>,
      buyer_email : '<%= %>',
      buyer_name : '<%= %>',
      buyer_tel : ' no phone ',
      buyer_addr : ' course name: no address',
      buyer_postcode : ' no postcode ',
      m_redirect_url: "https://url"
    }, function(rsp) {
      if ( rsp.success ) {// Successful payment: Successful payment approval or issuance of a virtual account
      // HTTP request using jQuery
          url: "<%= payment_complete_path(:item_id => @item) %>", // Merchant server
          method: "POST",
          headers: { "Content-Type": "application/json" },
          data: {
              imp_uid: rsp.imp_uid,
              merchant_uid: rsp.merchant_uid
      }).done(function (data) {

        // Logic executed on successful response from the merchant server through the payment API
      } else {
        var msg = '결제에 실패하였습니다.';
        msg += '에러내용 : ' + rsp.error_msg;
<% end %>

but after submitting the form the transaction goes through successfully but it stays on the page

how can I make it to go to this url or this action

  url: "<%= payment_complete_path(:item_id => @item) %>", // Merchant server

in my controller ?

Any help will be greatly appreciated. Thank you!

  $: 'jquery/src/jquery',
    jquery: 'jquery/src/jquery',

    jQuery: 'jquery/src/jquery',
    'window.jQuery': 'jquery',
    Popper: ['popper.js', 'default']

why does the one above work for one javascript but for other javascript to work I have to have this

  $: 'jquery',
  jQuery: 'jquery',
  'window.jQuery': 'jquery',
  Popper: ['popper.js', 'default']

This is in the environment.js

Posted in Trying to insert this without refreshing the page ~

I am trying to insert a new comment on to the page without reloading using stimulus and javascript ~ I tried following along Chris in the nested comments video (NOTE: my comment is like his POST not comment) but I am having trouble~ I was wondering if anyone could help
It saves to the database but it isn't inserting. (It shows up if I reload the page )

Here are the codes

In the comments controller after being saved

      respond_to do |format|
        format.html { redirect_to course_unit_reading_passage_path(@course, @lesson), notice: 'Comment was 
            successfully created.' }

Since the above code is in the create
I've created create.js.erb
here is the code

var replies_form = document.querySelector("#comments")
replies_form.insertAdjacentHTML('afterbegin', '<%=j render partial: "lessons/comments/comment", locals: { comment: @comment }, format: :html %>')

var form_reply = replies_form.querySelector("form")


And in the show page

      <div id="comments">   

          <%= render partial: 'lessons/comments/comment' %>

Here is the form for the comment

<%= form_with model: [@course, @lesson,  @comment], html: { class: local_assigns[:class], data: { target: local_assigns[:target]} } do |f| %>

  <div class ="form-group">
    <%= f.text_area :content, class: "form-control" %>
  <div class="form-group">
    <%= f.submit :class => "btn btn-success" %>
<% end %> 

NOTE: comments partial is in the comments folder nested inside courses
Any help would be greatly appreciated~
Thank you!

Is there a way to detect users leaving a page and alerting them in rails or would it be better to use jquery?
Thank you!

Posted in Liking Posts Discussion

It works on Rails 6 after adding this to
config > webpack > environment.js

const { environment } = require('@rails/webpacker')

const webpack = require('webpack')
  new webpack.ProvidePlugin({
    $: 'jquery/src/jquery',
    jquery: 'jquery/src/jquery',

    jQuery: 'jquery/src/jquery',
    'window.jQuery': 'jquery'

module.exports = environment

Posted in Duration of a video in the listing page

Thank you!!

Posted in Duration of a video in the listing page

Chris ~ May I ask how you are handling/doing the duration of the video on the listing page? Are you saving it in the database? if you are saving it in the database, which data type are you using? are you entering it manually? are you using a gem? Thank you!

Posted in Nested Comment Threads in Rails - Part 1 Discussion

Is there a follow-up episode for this? If there is ~ do you know where I can find this?

here is the asset_root: that i found
I was having hard time and I found this
it seems to work ~

Posted in Space Upgrades - A browser game made in Rails

wow !

Hello ~ I have been trying to figure out how to get the dropdown menu like the one in this forum to show the category after the page refreshes ~ I have been trying to do it using javascript and bootstrap ~ are there better ways to do it in rails? I have been stuck for hours :(

any guidance would be greatly appreciated.

Thank you!

logo Created with Sketch.

Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

© 2021 GoRails, LLC. All rights reserved.