Search code examples
ruby-on-railshrefbootstrap-4popoverlink-to

link_to in data-content for a bootstrap 4 popover


I want to put a link in the data-content of my popover. not using <% link_to 'Save it to your events', usersavedevents_path, method: :post %> because it doesn't work, it spews over into the UI.

view

<div class="col-1" tabindex="0" data-container="body" data-trigger="focus" data-toggle="popover" data-placement="top" title="Save" data-content="Not sure if you're going? <a rel='nofollow' data-method='get' href='/usersavedevents/new?user_id=1'>Save it to your events</a> and we'll remind you closer to the start date.">
                <%= image_tag "bookmark.png", height: '25px' %>
              </div>
<script>

              $(function () {
                $('[data-toggle="popover"]').popover(
                  {html : true
                  })
              })</script>
              <script>
              $('.popover-dismiss').popover({
                trigger: 'focus'
              })</script>

controller (I have it root_path for now just to test it out and see if i get action)

class UserSavedEventsController < ApplicationController
def new
    redirect_to root_path
end

def create
    redirect_to root_path   
end
end

routes

  resources :usersavedevents

Keep getting this error:

Routing Error
uninitialized constant UsersavedeventsController

Solution

  • I think your naming is wrong:

    routes.rb

    resources :user_saved_events
    

    Thus the path will be user_saved_events_path

    make sure your file name follows the Rails convention:

    user_saved_events_controller.rb
    

    Here's some doc on rails naming conventions