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. (?)
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?
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
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
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
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
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.
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
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
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
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....
!! #"index", :controller=>"medicals", :employee_id=>nil}, missing required keys: [:employee_id]>
!! #"show", :controller=>"medicals", :employee_id=>#}, missing required keys: [:id], possible unmatched constraints: [:employee_id]>
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
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
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
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... =)
ruby 2.6.1p33 (2019-01-30 revision 66950) [x86_64-linux]
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.