Nelson Casanova

Joined

2,720 Experience
0 Lessons Completed
3 Questions Solved

Activity

Posted in Implement Authentication Service in Rails

Hello,

I'm currently looking for options to create some form of authentication service based on Rails.

I've got several microservices like app1.site.com app2.site.com and app3.site.com and I would like to have something like auth.site.com so users only have to create their accounts once and use them across sites...

I don't think there's a Devise option that can be used. My research points to Okta or Auth0 which are now, very recently, the same apparently.

What's the right way to implement this? whether is through an external service provider or some other form of custom build application with the help of already existing gems.

Posted in Page enter with Turbolinks

Whoops! Got it. Navigate into the page with: <a href="/page" data-turbolinks="false"></a>

Posted in Page enter with Turbolinks

Good day,

I'm having an issue when entering a page and loading a resource. The resource is Selectize which otherwise working fine but when I enter the page with the functionality it will just not load selectize on the selected dropdown, instead, I need to fully refresh the page and it will work.

I tried adding data-turbolinks-action="replace" to the a tag linking to the page but that didnt work.

Also added:

document.addEventListener("turbolinks:load", function() {
$('#employer-list').selectize({
sortField: 'text'
});
});

to the bottom of the page but didn't work either... the only way of actually including Selectize functionality is by refreshing the page. (?) Is there a way of calling .selectize on page change or load?

Posted in Display Cloudinary image uploads

Hello,

I've been trying to solve a problem I've got when trying to display images from Cloudinary. I setup everyhting accounding to the guide they provide and basically I need to upload images from Trix editor. All this works ok. I can create a new 'post' and add images and I can see them get uploaded to Cloudinary but when I go to the actual post I see a broken link to the image.

It links to something like:
https://www.website.com/rails/active_storage/representations/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBEUT09IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--840bc40935cd84bca5e9d91a61a417548af73f46/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaDdCam9VY21WemFYcGxYM1J2WDJ4cGJXbDBXd2RwQWdBRWFRSUFBdz09IiwiZXhwIjpudWxsLCJwdXIiOiJ2YXJpYXRpb24ifX0=--e8b64f915dd57a02094ca6aabd25a6fa92ba975b/wvgq2bftvea31.png

and when I check the image over at Cloudinary the URL should be something like:

https://res.cloudinary.com/your-application/image/upload/v1599605569/mw5yd8iftpmzq7peqwjk8ot3htbw.png

My /views/active_storage/blobs/_blob.html.erb file looks like the default:

<figure class="attachment attachment--<%= blob.representable? ? "preview" : "file" %> attachment--<%= blob.filename.extension %>">
  <% if blob.representable? %>
    <%= image_tag blob.representation(resize_to_limit: local_assigns[:in_gallery] ? [ 800, 600 ] : [ 1024, 768 ]) %>
  <% end %>

  <figcaption class="attachment__caption">
    <% if caption = blob.try(:caption) %>
      <%= caption %>
    <% else %>
      <span class="attachment__name"><%= blob.filename %></span>
      <span class="attachment__size"><%= number_to_human_size blob.byte_size %></span>
    <% end %>
  </figcaption>
</figure>

Any ideas how to grab the image from the cloud instead of that weird looking local storage link?

Posted in Cannot add jQuery to Rails 6 projects

I've been trying to make a few apps work with Fomantic UI and the gem works fine, the problem is that to use calendars and modals you need jquery... No probs, I added that by following this guide and its still not working. On deployment, it will just not load jQuery at all. I've been forced to include cnd links on the application.html.erb to load jQuery, there must be a way of doing this. (?)

Posted in How to create a button with a file upload action

I've got a form where the user is allowed to import a spreadsheet. Currently the part for the user to select the file looks like:

<%= form_tag import_clearance_crews_path(@clearance), multipart: true, class: "ui form" do %>
  <%= file_field_tag :file, class: "ui button green" %>
  <%= submit_tag "Import", class: "ui button" %>
<% end %>

Which works ok, on clicking 'choose file' the user is allowed to pick up a file and then he needs to click 'import' to finalize the import...

I was wondering if there is a way to just have a button, once you click on it you can pick up a file and straight after selecting it just upload and redirect to X view?

Regards

Posted in Display non-image attachments with Trix/action_text

I've got the barebones functionality of Trix working ok... The editor displays ok and text and images display as expected. But when I drag and drop a PDF (for example) I can see in the editor a small box with the file title and size display, once its saved the only thing its displayed is, again, the file title and size with no link to a download or anything... the generated html looks promising as it includes some sort of json value inside a 'figure' tag but no idea how to display that...

Posted in Friendly URL's question

Right, got it. I just hope this is not going to cause major headaches in the future.

I installed friendly_id and add the gem functionality to the topic, forum and post models.

As expected I ended up with a url that looked like mysite.com/forums/off-topic/posts/hi-there not bad but still not optimal.

I added the following to my routes.rb:

resources :forums, :path => '' do
   resources :posts, :path => '' do
     end
end

Done. Like i said, I hope this is the right way...

Posted in Friendly URL's question

Hello,

I'm building a small forum for my website and its a very simple app with the schema looking a bit like:

Topic -> Forum -> Post

So, Topic can be 'Off-Topic' with a Forum called 'Introductions' and maybe a post titled 'Hi There'

In an ideal world the index is a list of Topics and each one displaying a link to its underlying Forums. Once you click a forum URL will look like: mysite.com/off-topic/ and once I click a post the URL looks like mysite.com/off-topic/hi-there

Currently what I've got looks more like mysite.com/forums/1/posts/1 feels like if I implement the friendly_id gem I will still end up with something like mysite.com/forums/off-topic/posts/hi-there. How can I achieve a url that does not include the model in it?

Posted in `simple_form` Date Selector

I've been working with the simple_form gem to create the forms in my app and I would like to know if anyone have experience replacing the default date selector? Its functional but a completely unacceptable alternative to a typical calendar date picker, simple_form uses three select lists, one per day/month/year respectively 😵.

The form tag its like: <%= form.input :birth_date %> so no real option to customize the output there...

Any help in using better a date selector for this gem is highly appreciated.

Amazing stuff!

Posted in ActiveRecord/Routing madness

I'm not sure whats happening here, I feel like I've done this successfully in the past but for some reason my app is crashing all over.

This is quite simple. Ive got a model Employees and it has a relationship with another model called Medicals. So basically each employee can have multiple medicals.

routes.rb looks like:

Rails.application.routes.draw do
  resources :employees do
    resources :medicals
  end
end

The MedicalsController.rb looks like:

class MedicalsController < ApplicationController
  def show
    @medical = Medical.find(params[:id])
  end

  def new
    @medical = Medical.new(employee_id: params[:employee_id])
  end

  def create
    @medical = Medical.new(medical_params)

    if @medical.save
      redirect_to @medical
    else
      render 'new'
    end
  end

  def edit
    @medical = Medical.find(params[:id])
  end

  def update
    @medical = Medical.find(params[:id])

    if @medical.update(medical_params)
      redirect_to @medical
    else
      render 'edit'
    end
  end

  private
  def medical_params
    params.require(:medical).permit(:employee_id, :date_signed, :date_valid, :medical_notes)
  end
end

And lastly views\medicals\new.html.erb looks like:

<%= simple_form_for @medical, url: employee_medicals_path(@medical) do |form| %>
  <%= form.input :date_signed %>
  <%= form.input :date_valid %>
  <%= form.button :submit %>
<% end %>

Im using the simple_form gem but that should be the issue, i would think...

Anyway, I'm getting the following error on

https://pasteboard.co/IjKcQTb.png

You can see in the live shell that I tried other paths to no avail... they all error out so I'm not sure whats missing here....

employee_medicals_path
=> "/employees/2/medicals"

employee_medicals_path(@medical)
!! #"index", :controller=>"medicals", :employee_id=>nil}, missing required keys: [:employee_id]>
employee_medical_path(@medical)
!! #"show", :controller=>"medicals", :employee_id=>#}, missing required keys: [:id], possible unmatched constraints: [:employee_id]>

medicals_path(@medical)
!! #:0x00007fc9e0992738>>

finally rake routes:

        employee_medicals GET    /employees/:employee_id/medicals(.:format)                                               medicals#index
                          POST   /employees/:employee_id/medicals(.:format)                                               medicals#create
     new_employee_medical GET    /employees/:employee_id/medicals/new(.:format)                                           medicals#new
    edit_employee_medical GET    /employees/:employee_id/medicals/:id/edit(.:format)                                      medicals#edit
         employee_medical GET    /employees/:employee_id/medicals/:id(.:format)                                           medicals#show
                          PATCH  /employees/:employee_id/medicals/:id(.:format)                                           medicals#update
                          PUT    /employees/:employee_id/medicals/:id(.:format)                                           medicals#update
                          DELETE /employees/:employee_id/medicals/:id(.:format)                                           medicals#destroy

Posted in Commontator with Trix

I should feel ashamed of myself but I'm gonna go ahead and confess that I should have tried a bit harder.

I changed the text_area to hidden_field and added <trix-editor input="comment_body"></trix-editor> commentbody being the same id as the now hidden field.

Posted in Commontator with Trix

Good day robots,

I'm trying to implement the Trix editor as the default editor for Commontator's comments.

The default Commontator view is defined as follows in app\views\commontator\comments\_form.html.erb:

<%= form_for([commontator, thread, comment],
             remote: !no_remote) do |f| %>
<div class="comment_form_field">
    <%= f.text_area :body, rows: '7' %>
    <%= javascript_tag('Commontator.initMentions()') if Commontator.mentions_enabled %>
</div>
<% end %>

So I get that I need to replace that text_area for the Trix default tag: <trix-editor input="???"></trix-editor> not sure what to put into the input parameter.

The generated HTML for the above form_for is as follows;

<form class="new_comment" id="new_comment" action="/commontator/threads/1/comments" accept-charset="UTF-8" data-remote="true" method="post">

<div class="comment_form_field">
    <div class="field_with_errors">
        <textarea rows="7" name="comment[body]" id="comment_body" spellcheck="false"></textarea>
    </div>
</div>

<div class="comment_form_actions">
    <input type="submit" name="commit" value="Post Comment" data-disable-with="Post Comment">
    <input type="submit" name="cancel" value="Cancel" data-disable-with="Cancel">
</div>

</form>

Any ideas? cheers!

oh! sweeeet! thats just the thing! I owe you a pint of guinness

Hello,

I'm currently doing some tests using Administrate to see if the functionality can be shaped in a way that is convenient for me... Some things have been quite easy and for the most part satisfactory, like arranging things in different ways, implementing rich text editing and such...

Right now I'm wondering if its possible to better the default implementation for BelongsTo what happens is you get a dropdown that calls data from the child table... So for the following schema...

  • Posts (id, title, category_id) - Categories (id, name)

...you will get Administrate to give you a dropdown of category names on creating a new post, thats fine if you have only 5 categs, but if you have 1000 then its gonna be a long scrolling to get the one you need. So again, I'm left here wondering if its some solution/gem that can be implemented to have a autocomplete field that can search on the child table for the desired value. Or maybe this functionality its built-in and I dont even know about it... =)

Regards!

Posted in "You must use Bundler 2 or greater..." Error

rails -v
Rails 5.2.3
ruby -v
ruby 2.6.1p33 (2019-01-30 revision 66950) [x86_64-linux]
bundler -v
Bundler version 2.0.1

On creating a new app and trying rake db:create i get: You must use Bundler 2 or greater with this lockfile. even after deleting the lockfile and re-running bundle install or bundle update I get the same thing. The only way to make it work is to run bundle exec rake db:create. But then, to run migrations it will just keep getting the same error message.

Any ideas?