Node Express fail load css and js - express

this is my folders:
/app
└── models
└── ...
└── node_module
└── ...
└── routes
└── ...
└── public
└── css
└── js
└── views
└── unites
└── new.js
└── show.js
└── edit.js
So, when I go on //mysiteweb/new my logs look like this:
GET /maitre-unites-new 304 4ms
GET /css/bootstrap.css 304 3ms
GET /js/bootstrap.js 304 2ms
But when I go on //mysiteweb/show my logs look like this:
GET /maitre-unites-show/52b46d81ddd1086615000001 304 2ms
GET /maitre-unites-show/css/bootstrap.css 404 2ms
GET /maitre-unites-show/js/bootstrap.js 404 1ms
GET /maitre-unites-show/images/unites/batiment1.jpeg 404 2ms
I don't understand why, my syntax is the same:
/*
* GET New unit.
*/
app.get('/maitre-unites-new', ensureAuthenticated, function (req, res){
Unites.find({}, function (err, unites) {
res.render('unites/new', {
unites: unites,
user : req.user,
title : ' Que voulez vous créer Maitre Du Jeu'
});
});
});
/*
* GET show unit.
*/
app.get('/maitre-unites-show/:id', ensureAuthenticated, function (req, res){
Unites.findById(req.params.id, function (err, unites) {
res.render('unites/show', {
unites: unites,
user : req.user,
title : ' Que voulez vous créer Maitre Du Jeu'
});
});
});
my views news.js:
<% layout('layout') -%>
<% script('js/bootstrap.js') -%>
<% stylesheet('css/bootstrap.css') -%>
<!-- Jumbotron -->
<div class="jumbotron">
<h1><%= title + ' ' %><code><%= user.username %></code></h1>
<p style="text-align:center;">Ho Créateur ! Inventez-nous comme toutes choses en cet univers.</p>
<p>
aide »
retour »
</p>
</div>
<div class="row">
<div class="col-md-12">
<h3>Créez une Unité:</h3>
<form method='post' action='/maitre-unites-new'>
<div>
<label>Nom:</label>
<input type="text" name="name"/><br/>
</div>
<div>
<label>Avatar:</label>
<input type="text" name="avatar"/><br/>
</div>
<div>
<label>Description:</label>
<textarea name="description" row="5" cols="50"></textarea>
</div>
<hr>
<%= unites.name %>
<h2>Inclure d'autres unités dans celle-ci:</h2>
<% if (unites && unites.length !=0) { %>
<div>
<% for (var index in unites) { %>
<input type="checkbox" name="<%= unites[index].unit %>" value="<%= unites[index]._id %>"> <%= unites[index].name %> |
<% } %>
</div>
<% } else { %>
<div>
no document exist
</div>
<% } %>
<hr>
<h2>Inclure cette unité dans d'autres unités:</h2>
<% if (unites && unites.length !=0) { %>
<div>
<% for (var index in unites) { %>
<input type="checkbox" name="<%= unites[index].unit %>" value="<%= unites[index]._id %>"> <%= unites[index].unit %> |
<% } %>
</div>
<% } else { %>
<div>
no document exist
</div>
<% } %>
<input type="submit" value="Save">
</form>
</div>
</div>
<!-- Site footer -->
<div class="footer">
<p>© Company 2013</p>
</div>
</div> <!-- /container -->
my views show.js:
<% layout('layout') -%>
<% script('js/bootstrap.js') -%>
<% stylesheet('css/bootstrap.css') -%>
<!-- Jumbotron -->
<div class="jumbotron">
<h1><%= title + ' ' %><code><%= user.username %></code></h1>
<p style="text-align:center;">Ho Créateur ! Inventez-nous comme toutes choses en cet univers.</p>
<p>
aide »
retour »
</p>
</div>
<div class="row">
<div class="col-md-12">
<%= unites.name %>
<img src="images/unites/<%= unites.avatar %>.jpeg">
<%= unites.description %>
</div>
</div>
<!-- Site footer -->
<div class="footer">
<p>© Company 2013</p>
</div>
</div> <!-- /container -->
This is my repo.git
Why I get this /maitre-unites-show/images.... and not /images... ?

Alright. The error is caused by the fact that your show route has extra path component /:id, and your routes in the views are relative, so they are searched from the current URL, which is different:
new -> /
show -> /maitre-unites-show/
All you need to do is to make your paths absolute in the view:
<% layout('layout') -%>
<% script('/js/bootstrap.js') -%>
<% stylesheet('/css/bootstrap.css') -%>

Related

Stripe token not being returned from rails vue.js form

I have a rails 5 application that is using vue.js. I have a input form that collecting basic information in addition to having a stripe element in it. The stripeV3 element loads with no problem, the client console does not display any javascript errors.When I fill out the form and submit it the expect stripeToken parameter that should come back from stripe is omitted. I not remotely sure why.
checkout.html.erb
<section class="hero">
<div class="container">
<div class="row">
<div class="col-md-6 col-sm-8 mx-auto">
<div class="card border-none">
<div class="card-body">
<p class="mt-4 lead text-center">
Shipping Address
</p>
<div class="mt-4 clearfix">
<%= form_for :customer_order, html: {id: 'payment-form'}, url: { action: "process_order" } do |f| %>
<div class="form-group">
<%= f.text_field :full_name, :class=>"form-control", :placeholder=>"Full Name" %>
</div>
<%if !current_user%>
<div class="form-group">
<%= f.text_field :guest_email, :class=>"form-control", :placeholder=>'Email' %>
</div>
<%end%>
<div class="form-group">
<%= f.text_field :street_address1, :class=>"form-control", :placeholder=>"Street and number, P.O. box" %>
</div>
<div class="form-group">
<%= f.text_field :street_address2, :class=>"form-control", :placeholder=>"Apartment, suite, unit, building, floor, etc" %>
</div>
<div class="form-group">
<%= f.text_field :city, :class=>"form-control", :placeholder=>"City" %>
</div>
<div class="form-group">
<%= f.select(:state, options_for_select(['AL', 'AK', 'AZ', 'AR', 'CA', 'CO', 'CT', 'DC', 'DE', 'FL', 'GA', 'HI', 'ID', 'IL', 'IN', 'IA', 'KS', 'KY', 'LA', 'ME', 'MD', 'MA', 'MI', 'MN', 'MS', 'MO', 'MT', 'NE', 'NV', 'NH', 'NJ', 'NM', 'NY', 'NC', 'ND', 'OH', 'OK', 'OR', 'PA', 'RI', 'SC', 'SD', 'TN', 'TX', 'UT', 'VT', 'VA', 'WA', 'WV', 'WI', 'WY'])) %>
</div>
<div class="form-group">
<%= f.text_field :zip_code, :class=>"form-control", :placeholder=>"Zip code" %>
</div>
<div class="form-group">
<label for="card-element">
Credit or debit card
</label>
<div id="card-element">
<!-- A Stripe Element will be inserted here. -->
</div>
<!-- Used to display form errors. -->
<div id="card-errors" role="alert"></div>
</div>
<br><br>
<%= f.submit 'Continue Checkout', :class=>"btn btn-primary float-right" %>
<% end %>
</div>
</div>
</div>
</div>
<div class="clearfix"></div>
</div>
</div>
</section>
<% content_for :javascript_section do %>
<script type="text/javascript">
var stripe = Stripe('pk_test_a_valid_test_token');
// Create an instance of Elements.
var elements = stripe.elements();
// Custom styling can be passed to options when creating an Element.
// (Note that this demo uses a wider set of styles than the guide below.)
var style = {
base: {
color: '#32325d',
lineHeight: '18px',
fontFamily: '"Helvetica Neue", Helvetica, sans-serif',
fontSmoothing: 'antialiased',
fontSize: '16px',
'::placeholder': {
color: '#aab7c4'
}
},
invalid: {
color: '#fa755a',
iconColor: '#fa755a'
}
};
// Create an instance of the card Element.
var card = elements.create('card', {style: style});
// Add an instance of the card Element into the `card-element` <div>.
card.mount('#card-element');
// Handle real-time validation errors from the card Element.
card.addEventListener('change', function(event) {
var displayError = document.getElementById('card-errors');
if (event.error) {
displayError.textContent = event.error.message;
} else {
displayError.textContent = '';
}
});
// Handle form submission.
var form = document.getElementById('payment-form');
form.addEventListener('submit', function(event) {
event.preventDefault();
stripe.createToken(card).then(function(result) {
if (result.error) {
// Inform the user if there was an error.
var errorElement = document.getElementById('card-errors');
errorElement.textContent = result.error.message;
} else {
// Send the token to your server.
stripeTokenHandler(result.token);
}
});
});
function stripeTokenHandler(token) {
// Insert the token ID into the form so it gets submitted to the server
var form = document.getElementById('payment-form');
var hiddenInput = document.createElement('input');
hiddenInput.setAttribute('type', 'hidden');
hiddenInput.setAttribute('name', 'stripeToken');
hiddenInput.setAttribute('value', token.id);
form.appendChild(hiddenInput);
// Submit the form
form.submit();
}
</script>
<% end %>
application.js
// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, or any plugin's
// vendor/assets/javascripts directory can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file. JavaScript code in this file should be added after the last require_* statement.
//
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require jquery3
//= require bootstrap
//= require turbolinks
//= require rails-ujs
//= require popper
//= require_tree .
//= require_self
//= require vue.min.js
//= require vue-carousel.js
//= require_directory ./components
Vue.use(VueCarousel);
const Carousel = VueCarousel.Carousel;
const Slide = VueCarousel.Slide;
$(document).on('turbolinks:load', function() {
new Vue({
el: '#app',
components: {
Carousel,
Slide,
Slider,
}
});
});

Can't save date time fields to database

I have model with date time field after render new view and submit it all fields of model saved to database except date time field even I am using date time picker
Can any body help me to solve this problem
This is the code I am working on:
Interview controller
def new
#interview = Interview.new(:batch_id => #batch.id)
end
def create
#interview = Interview.new(interview_params)
# Save the object
if #interview.save
# If save succeeds, redirect to the index action
flash[:notice]= "تم إنشاء المقابلة بنجاح."
redirect_to(interviews_path(:batch_id => #batch.id))
else
# If save fails, redisplay the form so user can fix problems
render('new')
end
end
Interview new view code
<% #page_title = "إنشاء مقابلة" %>
<div id="content-header">
<div class='header-icon hr-icon'></div>
<h1>المقابلات</h1>
<div class='header-sep'>|</div>
<div class='sub-header'>إنشاء مقابلة</div>
<div id="inner-tab-menu">
<ul>
<li class='themed_bg themed-dark-hover-background'><%= link_to("<< العودة للجدول", interviews_path(:batch_id => #batch.id)) %></li>
</ul>
</div>
</div>
<div id="page-yield">
<div class="iterviews new">
<%= form_for(#interview, :url =>interviews_path(:batch_id => #batch.id)) do |f| %>
<%= render(:partial => 'form', :locals => {:f => f}) %>
<script type="text/javascript">
$(function () {
$('#datetimepicker1').datetimepicker();
locale: 'ar-sa'
});
</script>
<div><%= f.submit("إنشاء مقابلة", :class => 'submit_button') %></div>
<% end %>
</div>
</div>
form code
<div class="label-field-pair">
<div class="right-column">
<label for="student_grade">رقم المقابلة<span class="necessary-field">*</span> </label>
<div class="text-input-bg"><%= f.text_field(:code, style: "width: 240px;") %></div>
</div>
</div>
<div class="label-field-pair">
<div class="right-column">
<label for="student_grade">تاريخ المقابلة<span class="necessary-field">*</span></label>
<div class="text-input-bg" style="direction: ltr; margin: 0 10px 0 0;">
<div class='input-group date' id='datetimepicker1'>
<%= f.datetime_field(:interview_date , class: "form-control", style: "width: 200px;margin: 0;") %>
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
</div>
</div>
</div>
<%= f.hidden_field(:batch_id, value: #batch.id) %>
I could find out the solution for this problem, of course the reason was that datetimepicker doesn't understand the values in my fields so what I did is the following:
1- change the numbers in moment-with-locales.js in the 'ar-sa' section from Indian numbers to Arabic numbers.
2- set the format: option to datetimepicker to match model attribute data type format in case it is date type or datetime type
and that's solve my problem

Include Local javascript file with global dependency for only a view

I have a view like this
#model IEnumerable<DuckingOctoBear.Models.PostViewModel>
<p>
#if (User.IsInRole("Administrator") || User.IsInRole("Editor"))
{
#Html.ActionLink("Create New", "Create")
}
</p>
<div class="">
#foreach (DuckingOctoBear.Models.PostViewModel item in Model)
{
<a href="/Posts/Details/#item.Post.Id" class="post-element">
<h4>#Html.DisplayFor(modelItem => item.Post.Title)</h4>
<h6>
Inserted by #item.User.UserName at #item.Post.Date.ToString("dd MMMM yyyy hh:ss")
</h6>
<article>
#Html.Raw(item.Post.Text)
</article>
<span>
#if (User.IsInRole("Administrator") || User.IsInRole("Editor"))
{
#Html.ActionLink("Edit", "Edit", new { id = item.Post.Id })
<span>|</span>
}
#Html.ActionLink("Details", "Details", new { id = item.Post.Id })
<span>|</span>
#if (User.IsInRole("Administrator"))
{
#Html.ActionLink("Delete", "Delete", new { id = item.Post.Id })
<span>|</span>
}
</span>
</a>
}
</div>
...where I would like include a Javascript file which have strong dependencies to other Javascript files already included in the _Layout.cshtml
<div class="container body-content">
#RenderBody()
<hr />
<footer>
<p>© #DateTime.Now.Year - My ASP.NET Application</p>
</footer>
</div>
#Scripts.Render("~/bundles/jquery")
#Scripts.Render("~/bundles/bootstrap")
How can I include that local file without register it in a bundle, and so for all views?
Ok epic fail
for this _Layout.cshtml
<div class="container body-content">
#RenderBody()
<hr />
<footer>
<p>© #DateTime.Now.Year - My ASP.NET Application</p>
</footer>
</div>
#Scripts.Render("~/bundles/jquery")
#Scripts.Render("~/bundles/bootstrap")
#RenderSection("scripts", required: false)
I could add just a new section
#RenderSection("LocallyScriptLibrary", required: false)
then in the target view doing just:
#section LocalScriptLibrary{
<script src="~/Scripts/LocalLibrary.js"></script>
}

Rails Link_to image tag isnt retrieving image from database

I'm brand new to rails (and coding in general) so I've a quick question on retrieving images from a database
Running rails 3.2.8
I have a list of products, code, description, price and product_image in the database, The product images is stored as 123.jpg in the database and the image itself is stored in app/assets/images folder
In my view I have the following code
<div class="center_content">
<div class="center_title_bar">Latest Products</div>
<% #camera_catalogues.each do |camera_catalogue| %>
<div class="prod_box">
<div class="top_prod_box"></div>
<div class="center_prod_box">
<div class="product_title"><%= camera_catalogue.model_description %></div>
<div class="product_img"><%= link_to (image_tag camera_catalogue.product_image),camera_catalogue %></div>
<div class="prod_price"><span class="reduce">350$</span> <span class="price"><%=number_to_currency(camera_catalogue.price, :unit =>"€")%> </span></div>
</div>
<div class="bottom_prod_box"></div>
<div class="prod_details_tab">
<img src="assest/cart.gif" alt="" title="" border="0" class="left_bt" />
<img src="assest/favs.gif" alt="" title="" border="0" class="left_bt" />
<img src="assets/favorites.gif" alt="" title="" border="0" class="left_bt" />
details
</div>
</div>
Everything displays correctly except that the image is not retrieved from the database
which is this line
<div class="product_img"><%= link_to (image_tag camera_catalogue.product_image),camera_catalogue %></div>
Does the image in the database need to be saved with a different url. i.e. instead of 123.jpg it is saved as assets/123.jpg
or is there some other error in my code.
Help/advice greatly appreciated :)
Use it like this
<div class="product_img"><%= link_to (image_tag (camera_catalogue.product_image)),camera_catalogue %></div>
I guess it will work for you. You need not use 'assests/image_name'

Controller doesn't receive all parameters within the form

In my MVC Web App I am running an ActionResult with the following signature:
Public Function Create(ByVal article As Article_Ad) As ActionResult
And in my ASPX page I have declared the following form which fields correspond to the model, which is strongly typed:
<% Using Html.BeginForm(ViewData("action").toString, "Article", FormMethod.Post, New With { .class = "basic"}) %>
<div class="inner-form">
<%= Html.MyValidationSummary("Por favor corrija os erros e tente novamente.")%>
<dl>
<dt><label for="name">Descrição:</label></dt>
<dd><%= Html.TextBox("description", Model.description, New With {.class = "txt"})%></dd>
<dt><label for="type">Tipo:</label></dt>
<dd><%= Html.DropDownList("type", New SelectList(ViewData("typeList"), "value", "text", Model.type), New With {.class = ""})%></dd>
<dt id="image_dt"></dt>
<dd id="image_dd">
<fieldset id="img_fieldset">
<legend style="font-weight: bold;">Imagem</legend>
<label for="portrait_image_url">Url da Imagem:</label>
<%= Html.TextBox("image_url", Model.image_url, New With {.class = "txt"})%>
<label for="portrait_bigimage_url">Url da Imagem Portrait:</label>
<%= Html.TextBox("portrait_bigimage_url", Model.portrait_bigimage_url, New With {.class = "txt"})%>
<label for="landscape_bigimage_url">Url da Imagem Landscape:</label>
<%= Html.TextBox("landscape_bigimage_url", Model.landscape_bigimage_url, New With {.class = "txt"})%>
</fieldset>
</dd>
<dt id="video_dt"></dt>
<dd id="video_dd">
<fieldset id="video_fieldset">
<legend style="font-weight: bold;">Video</legend>
<label for="video_url">Url do Video:</label>
<%= Html.TextBox("video_url", Model.video_url, New With {.class = "txt"})%>
<label for="video_fullscreen">Url do Video Fullscreen:</label>
<%= Html.TextBox("video_fullscreen", Model.portrait_bigimage_url, New With {.class = "txt"})%>
</fieldset>
</dd>
<dt></dt>
<dd><input class="button" type="submit" name="submitButton" value="Gravar" /> <input class="button" type="submit" name="submitButton" value="Cancelar" /></dd>
</dl>
</div>
<% End Using%>
What is happening right now is that when I submit this form, only the description property is assigned to my object.
I'd like to know why the other properties aren't being filled in my class (I checked with fiddler and everything is being sent correctly).
Make sure your properties are in your Model.
Also you can make sure you View inherits your Model to get intellisense for it.
Inherits="System.Web.Mvc.ViewPage(Of Your Model)" %>