Middleman and Sinatra Contact Form rendering template - css

I'm trying to create a middleman site with a contact form using sinatra and pony gem
I'm having problems getting middleman and sinatra to play nicely together
THE ISSUE:
"
My Contact From is not rendering my header and footer and also does not like it when I try to include view helpers like = link_to tags When I try that I get this error
undefined method `link_to' for
Its also not picking up my stylesheets
"
Heres my Mailer.rb get method
class MailForms < Sinatra::Base
set :views, Proc.new { File.join(root)}
get '/' do
haml :contact, :layout => :'/contact'
end
end
and it lives in source/mailer.rb
when I go to website.com/contact.hml
I get the form but it has no header or footer all my other pages have them and is working
I can't use = link_to tags or image tags i get an undefined method error
Its also not picking up my styles
heres my config.rb
require 'source/mailer'
map('/contact.html') do
run MailForms
end
set :css_dir, 'stylesheets'
set :js_dir, 'javascripts'
set :images_dir, 'images'
set :relative_links, true
configure :build do
activate :relative_assets
end
heres my layout.haml with my stylesheet link
!!!
%html
%head
%meta{charset: "utf-8"}
%meta{content: "IE=edge,chrome=1", "http-equiv" => "X-UA-Compatible"}
%title= current_page.data.title || "Auto Tint Specalist"
%link{href: "//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css", rel: "stylesheet"}
= stylesheet_link_tag "normalize", "all"
%script{src: "//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"}
= javascript_include_tag "all"
%body{class: page_classes}
= partial 'layouts/header'
= yield
= partial 'layouts/footer'
all my styles are in all.scss in the stylesheets folder

Related

flatpickr via rails importmap not being generated

Attempting to use flatpickr as a UI for setting a date field with Rails 7.0.1 and ruby 3.1. When clicking on the input field, the expected 2 months of calendars is not rendered & in fact, nothing is registered in the browser network tab.
After bin/importmap pin flatpickr rails pinned the library to the cdn in the importmap.rb file:
pin "flatpickr", to: "https://ga.jspm.io/npm:flatpickr#4.6.9/dist/flatpickr.js"
application.js has the initially generated import "controllers".
flatpickr_controller.rb was created in the javascript/controllers directory with
import { Controller } from "#hotwired/stimulus"
import flatpickr from "flatpickr"
export default class extends Controller {
connect() {
this.config = {
enableTime: false,
dateFormat: 'Y-m-d',
}
}
}
The view partial invokes:
<%= form_with model: promo do |f| %>
<%= f.text_field :date_from, placeholder: t(".select"), data: { controller: "flatpickr" } %>
<% end %>
while the controller sets
#promos = Promo.up_comings(60)
#promo = Promo.new
#next_promo = Promo.next
#dates_to_disable = #promos.pluck(:date_from)
Why is the calendar not rendering?
I am also confused as to where to place the different flatpickr options: in the controller, or straight into the form date element.
The issue is related to support for Stimulus 3. Pin as follows:
bin/importmap pin stimulus-flatpickr#beta
Also reference some css source, such as to the latest version
<link rel="stylesheet" href="https://ga.jspm.io/npm:flatpickr#4.6.9/dist/flatpickr.min.css">
otherwise the input field will be deemed as readonly...

Rails Variables inside the CSS file

I have CSS file that needs to be embedded by the user. Now for the user to customize the CSS file as he/she wishes (change the colors and font-size mainly) I have to store that information in database file, append that information to specfic CSS file and then enable that user to embed it.
I would get the id of the User that I wish to change. So color codes stored are basically extracted from,
User.find(params[:id]).main_color
# This would return => #fffff
This what my embed code looks like right now,
<link href="link.com/initial.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" data-user="18" src="link.com/some_file.js" />
Here data-user is the id of the user who is modifying the CSS file. (The IFrame is being embedded using the javascript file)
How should I modify my embed code and fetch the custom variables from my database in order to make the CSS cstomizable as the user wants?
Thanks in advance.
P.S I have thought of rewriting the CSS in the view(.html.erb file) and using !important there along with proper color codes selected by the user but that approach is not exactly very efficient.
I think the best way is to keep your script file at the server side, So you can easily modify your script depending on user database options
for example:
place a new route in routs.rb
post '/users/modify_style', :to => 'users#modify_style', :as => modify_style
then allow the route to respond to user by JavaScript file, for example if the user needs to change the main color of HTML template using a button or a link; so the form button in template may look like:
<%= button_to 'apply style', modify_style_path, :data => {:user_id => current_user.id}, :remote => true %>
or
<%= link_to 'apply style', modify_style_path(:user_id => current_user.id), :method => :post, :remote => true %>
so remote: true option will allow sending data to server through AJAX without refreshing the page.
at users_controller.rb
def modify_style
user = User.find(params[:user_id])
#main_color = user.main_color
respond_to do |format|
format.js { render 'some_file.js.erb' }
end
end
and in your js file:
$('#some_element_id_to_change_color_for').css('color', '<%= #main_color %>')
or you can add modify_style action code directly to the original action which load your page to appy user style once the page is loaded.
I would suggest you to directly use it in the erb file something like
my.html.erb
<html>
<!-- my html -- >
</html>
<style>
<%= my_css.html_safe %>
</style>

Are Rails 4 path_helpers broken with singular resources?

I am using Rails 4.0.0 with Mongoid and HAML I have the following model structure:
class Merchant
has_one :setting
end
class Setting
belongs_to :merchant
has_many :categories
end
class Category
belongs_to :setting
end
Setting is layed out as singular resource by intention. So I have these routes:
resources :merchants do
resource :setting, only: [:show, :edit, :update] do
resources :categories
end
end
When I make use of the standard form helpers to create a form for categories like so:
= form_for([#merchant, #setting, #category]) do |f|
and I edit a category, I get the following HTML:
<form accept-charset="UTF-8" action="/merchants/5257cfdf16abe9985c000002/setting/categories/5257cfdf16abe9985c000003" class="edit_category" id="edit_category_525c090a16abe9988f000001" method="post">
which is wrong. The category_id should be 525c090a16abe9988f000001 as in the form_tag's id attribute, but is not.
I encounter a similarily strange behaviour with all polymorphic_path helpers when it comes to singular resources. I am sure, I'm doing something wrong here. Or is there a problem with path_helpers and polymorphic_path helpers in Rails 4?

Admin changes themes

I am making a web-app which admin can change the themes. So I have 2 css files, style.css and style2.css.
In my application_helper I have
def set_themes(themes)
#themes = themes
end
in application_controller I have
helper_method :themes
And I put this on application.html.erb
<%= stylesheet_link_tag set_themes %>
And in Admin index.html I write a select_tag, like this :
Choose themes: <%= select_tag(:themes, options_for_select({"Black" => "compiled/styles", "Green" => "compiled/styles2"}), :onchange => 'set_themes(this.options[this.selectedIndex].value)') %>
And I got ArgumentError. I know that the problem is how I used onchange, because when I change manually from application_helper, it works. But I have no idea how to call methode from application_helper by clicking select_tag.
Can anyone help me? Thank youu :-)
Your definition of the set_themes method requires that the helper method be passed exactly one argument, but in this line:
<%= stylesheet_link_tag set_themes %>
you appear to be invoking it without any arguments (i.e., it is equivalent to calling set_themes()). You should change the call to set_themes in the line above to something else which has the proper arguments, or a direct instance variable, etc.

Add custom template in CKEditor 3 using classic ASP

I have a website that uses classic ASP to render settings for CKEditor 3.
On the serverside I have:
<%
Dim Editor
Set Editor = New CKEditor
Editor.basePath = "/ckeditor/"
Editor.Config("contentsCss") = "/Styles/Editor.css"
Editor.Config("templates_files") = "/templates/news.js"
Editor.Config("width") = 570;
Editor.editor "Html", Html
Set Editor = Nothing
%>
And in news.js I have:
CKEDITOR.addTemplates('news',
{
imagesPath: CKEDITOR.getUrl('/JavaScripts/ckeditor_3.6.3/templates/images/'),
templates:
[
{
title: 'News Template',
//image: 'template1.gif',
html:
'<h3>Template 2</h3>' +
'<p>Type your text here.</p>'
}
]
});
And it renders:
<script type="text/javascript" src="/ckeditor/ckeditor.js?t=C3HA5RM"></script>
<script type="text/javascript">//<![CDATA[
CKEDITOR.replace('Html', {"contentsCss": "\u002FStyles\u002FEditor.css","templates_files": "\u002Ftemplates\u002Fnews.js","width": 570});
//]]></script>
It seems like it takes the path provided (/templates)... and does a 404 with each letter from it.... i.e /t /e /m ...
What might be missing?
According to the documentation, the templates_files should be an array of strings, even if you use only one file, so the correct configuration is
Editor.Config("templates_files") = Array("/templates/news.js")

Resources