spacerobotTR
Joined
Activity
Interesting. Thanks!
This is great!
Can action mailbox be used with a gmail account or does it have to be one of the services listed?
I am having an issue deploying a site with stimulus via capistrano. I get the error:
ModuleNotFoundError: Module not found: Error: Can't resolve './controllers' in '/home/deploy/site/releases/20190501124321/app/javascript/packs'
My directory is:
App/javascript/packs/controllers. Inside packs I have application.js which references ./controllers.
Any ideas why this is failing?
UPDATE: I figured it out. My controllers folder didn't have anything in it yet and was not syncing.
Very cool. Thank you!
I sort of do this with a comment system I built with this. I just give the divs different ID's like this:
<div class="feed-element" id="<%= dom_id(comment) %>">
I loop through all comments related to a project and any of them can be inline edited. I would think it should be similar to different fields maybe?
I figured it out! In my LDAP.yml file the production connection section was indented by one space. This was causing it to not load the config correctly. Everything is working now. This was a great guide.
Chris in regards to the show page mentioned above what would the syntax look like to just display the one item on the show page? Not too familiar with arrays to know how to set that up.
I figured it out. Somehow must have removed the reference to include the application.js file in my application.html.erb. Adding that back in has resolved the issue!
Ahhh gotcha. I'll have to chase that down then. Thanks for the help.
So changing the link to this:
url_for(controller: :projects, action: :delete_upload, id: @project.id, upload_id: upload.id), method: :delete, data: { confirm: 'Are you sure?' }
Adding the method: delete produces this error:
No route matches [GET] "/projects/1/delete_upload/2"
I have a projects model. A project could have many uploads that could be anything (pdf, word, cad, image etc.) I have the uploading working and I am displaying links to the files on the projects/show page. I want to have a delete button next to the file links to be able to purge them when the link is clicked. I am getting all sorts of routing errors though.
When I click the Remove link_to I am getting the error: No route matches [GET] "/projects/1/delete_upload/2"
Any help or suggestions would be appreciated!
Here is what I have:
Projects Controller:
class ProjectsController < ApplicationController
before_action :set_project, only: [:show, :edit, :update, :destroy]
# GET /projects
# GET /projects.json
def index
@projects = Project.joins(:proj_status).order("created_at DESC")
@title = 'Projects - Summary'
end
# GET /projects/1
# GET /projects/1.json
def show
@projects = Project.joins(:proj_status).order("created_at DESC")
end
def delete_upload
@attachment = ActiveStorage::Attachment.find(params[:upload_id])
@attachment.purge # or use purge_later
redirect_back(fallback_location: projects_path)
end
# GET /projects/new
def new
@project = Project.new
end
# GET /projects/1/edit
def edit
end
# POST /projects
# POST /projects.json
def create
@project = current_user.projects.build(project_params)
respond_to do |format|
if @project.save
format.html { redirect_to @project, notice: 'Project was successfully created.' }
format.json { render :show, status: :created, location: @project }
else
format.html { render :new }
format.json { render json: @project.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /projects/1
# PATCH/PUT /projects/1.json
def update
respond_to do |format|
if @project.update(project_params)
format.html { redirect_to @project, notice: 'Project was successfully updated.' }
format.json { render :show, status: :ok, location: @project }
else
format.html { render :edit }
format.json { render json: @project.errors, status: :unprocessable_entity }
end
end
end
# DELETE /projects/1
# DELETE /projects/1.json
def destroy
@project.destroy
respond_to do |format|
format.html { redirect_to projects_url, notice: 'Project was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_project
@project = Project.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def project_params
params.require(:project).permit(:projname, :startdate, :enddate,
:installer, :createdby, :cpdcprojnum, :projmanager, :customername, :customerphone,
:customeremail, :projtype, :building, :rooms, :description, :status_id, uploads: [])
end
end
Projects Show page:
<% @project.uploads.each do |upload| %>
<li class="list-group-item">
<div class="media align-items-center">
<div class="media-body px-2">
<%= link_to upload.filename, rails_blob_path(upload, disposition: :attachment) %> -
<%= link_to 'Remove', url_for(controller: :projects, action: :delete_upload, id: @project.id, upload_id: upload.id), data: { confirm: 'Are you sure?' } %>
</div>
<a href="javascript:void(0)" class="d-block text-light text-large font-weight-light">×</a>
</div>
</li>
<% end %>
Routes:
resources :projects do
member do
delete "delete_upload/:upload_id", action: :delete_upload
end
end
I'm looking into this also. Did you find a solution? I'm looking for a link to delete individual uploads.
Listen 80 Listen 8080 <VirtualHost *:80> PassengerRuby /home/user/.rbenv/shims/ruby ServerName mysite.com ServerAlias site1.com ServerAdmin webmaster@localhost.com RailsEnv production DocumentRoot /home/user/rails/site1/public/ ErrorLog /home/user/rails/site1/log/error.log CustomLog /homeuser/rails/site1/log/access.log combined <Directory "/home/user/rails/site1/public/"> Options FollowSymLinks Require ip 111.111.0.0/16 Options -MultiViews </Directory> <LocationMatch "/home/user/rails/site1/public"> order deny,allow deny from all allow from 111.111.0.0/16 </LocationMatch> <VirtualHost *:8080> PassengerRuby /home/user/.rbenv/shims/ruby ServerName mysite2.com ServerAlias site2.com ServerAdmin webmaster@localhost.com RailsEnv production DocumentRoot /home/user/rails/site2/public/ ErrorLog /home/user/rails/site2/log/error.log CustomLog /home/user/rails/site2/log/access.log combined <Directory "/home/user/rails/site2/public/"> Options FollowSymLinks Require ip 111.111.0.0/16 Options -MultiViews </Directory> <LocationMatch "/home/user/rails/site2/public"> order deny,allow deny from all allow from 111.111.0.0/16 </LocationMatch>
This is my hosts file:
127.0.1 Localhost 127.0.1.1:80 site1.com 127.0.2.1:8080 site2.com
Both URLs display the content for site1.com
What am I missing here?
Error: Missing target element "inlineEdit.form"
Error: Missing target element "inline-edit.form"
Form
<%= form_for([@servicerequest, @comment || @servicerequest.comments.build], remote: true, class: local_assigns[:class], data: {target: "inline-edit.form"}) do |f| %> <div> <%= error_messages_for(f.object) %> </div> <div> <%= f.text_area :content, class: 'form-control', autofocus: true %> </div> <div style="padding-top:20px;"> <%= f.submit class: "btn btn-primary" %> </div> <% end %>
_comments partial:
<div class="feed-element" id="<%= dom_id(comment) %>" data-controller="inline-edit"> <div class="media-body" style="font-size:14px;"> <span class="pull-right text-navy"><%= time_ago_in_words(comment.updated_at) %> ago</span> <strong><%= comment.user.username %></strong> updated this service request. <br> <small class="text-muted"><%= @servicerequest.created_at.to_time.strftime('%B %e at %l:%M %p') %></small> <div class="well" style="font-size:14px;"> <div data-target="inline-edit.content" data-action="click->inline-edit#toggle"><%= comment.content.html_safe %></div> <% render "comments/form", comment: comment, class: "hidden" %> <% if current_user.username == comment.user.username %> <div class="actions"> <%= link_to "Edit", edit_servicerequest_comment_path(comment.servicerequest, comment), :remote => true, class: 'btn btn-xs btn-primary' %> <%= link_to "Delete", [@servicerequest, comment] , method: :delete, :remote => true, data: { confirm: 'Are you sure?' }, class: 'btn btn-xs btn-outline btn-inverse' %> </div> <% end %> </div> </div> </div>
within servicerequests/show:
<%= render 'comments/form', comment: @comment, class: "hidden" %> <div id="commentdiv"> <%= render @comments %> </div>
inline_edit_controller.js
import { Controller } from "stimulus" export default class extends Controller { static targets = [ "content", "form" ] toggle() { this.contentTarget.classList.add("hidden") this.formTarget.classList.remove("hidden") } }
Any ideas on why the content field hides when toggled but the form never appears?