Nelson Casanova

Joined

1,770 Experience
0 Lessons Completed
2 Questions Solved

Activity

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?

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

© 2020 GoRails, LLC. All rights reserved.