I'm trying to make a modal form pop up to add a new comment.
HTML Snippet
Add Comment
<div id="add_ac" class="modal">
<div class="modal_content">
<%= render '/s_comments/form' %>
</div>
</div>
I'm trying to use the link to trigger the modal
This is in the javascript file for the model (admin.js)
$('.modal-trigger').leanModal({
dismissible: true
});
According to the materialize css documentation that should work.
The following is in the headers for my application.js file
//= require jquery2
//= require jquery_ujs
//= require turbolinks
//= require materialize-sprockets
//= require_tree .
Thank you.
You need to initialize materialize modals within your document ready function:
$(document).ready(function(){
// the "href" attribute of .modal-trigger must specify the modal ID that wants to be triggered
$('.modal-trigger').leanModal();
});
After this they should show up.
Still you need to make your rails form ready for the modals, I found a guide for this here: http://www.jetthoughts.com/blog/tech/2014/08/27/5-steps-to-add-remote-modals-to-your-rails-app.html
I know this question is really old, but I wanted to share just in case someone else was running into this problem.
If you are using TurboLinks (which is standard in Rails) then the javascript that attaches listeners to buttons needs to go in the body instead of the head of the document. TurboLinks replaces the body only so when you load a new page, the javascript doesn't get run again.
You are initializing a modal class of "modal-trigger",
$('.modal-trigger').leanModal({
dismissible: true
});
but you are not calling / referencing the class in your anchor tag
Add Comment
so you just need to add "modal-trigger" in your anchor tag
Add Comment
and it should work, also I don't know why you are using data-toggle.
Related
I would like to use turbolinks in a rails 4 application but not have it replace the entire <body> tag. Instead I would like to specify a tag/selector for turbolinks to refresh.
Something like...
<body>
<div class="turbolinks-refreshes-this">
Some content that is replaced whenever a link is clicked.
</div>
<div class="turblinks-does-not-refresh-this">
Some content that remains even if a link is clicked.
</div>
</body>
My guess is you would need to fork turbolinks to add this functionality but thought I'd throw it out there to see if anyone else has tried to do this.
Have you looked at pjax? It's very similar to Turbolinks (and gets a mention in the Turbolinks README) but lets you specify a target container. Here's a Railscast that shows how to use it in a Rails app.
Here's a (slightly modified) excerpt from the pjax README:
<h1>My Site</h1>
<div class="container" id="pjax-container">
Go to next page.
</div>
We want pjax to grab the url /page/2 then replace #pjax-container
with whatever it gets back. No styles or scripts will be reloaded and
even the h1 can stay the same - we just want to change the
#pjax-container element.
We do this by telling pjax to listen on a tags and use
#pjax-container as the target container:
$(document).pjax('a', '#pjax-container')
Now when someone in a pjax-compatible browser clicks "next page" the
content of #pjax-container will be replaced with the body of
/page/2.
I am working on a django project that relies on angularjs and having trouble implementing angular-ui-router framework.
As mentioned in documentation I have included ui.router as a dependency,
app = angular.module('myApp',['restangular','ui.router',])
configured the states as follows,
app.config(['$stateProvider',function($stateProvider){
$stateProvider.state('landing',{
url: '/',
template:"<p> somethings here.</p>"
})
}]);
in base.html file i bootstrap the django project with angularjs as required
ng-app=myApp.
and in index.html which inherits base.html
<div ui-view>
<i>nothing here but this text</i>
</div>
my urls.py,
url(r'^$',home,name="homepage")
This does not work, ui-router never includes the inline template in index.html. index.html always loads nothing here but this text. I have looked at as much questions asked here but are not helping. What am I missing, is this specific to django?
I would say that these lines should make it:
app.config(['$urlRouterProvider',function($urlRouterProvider){
$urlRouterProvider.otherwise('/');
}]);
Check the working plunker here
Also check:
otherwise() for invalid routes
I am building a website with Yesod that contains a search form at the top of every page. From what I have understood till now, I should create a widget for the form, but I am unable to include it in a common place. What is the recommended way to do this?
If I create a custom widget, what is the recommended folder structure to follow?
This is what the defaultLayout function is intended for: you can add any kind of content to this page, and all pages of your site which use defaultLayout will inherit it automatically.
I ran into this recently when trying to add a header to every page that has a "Login" link if the user is not authenticated, and a "Logout" link if they are. I didn't find any good examples in the documentation of how to do this so I put one together.
Note: This assumes that you are using the scaffolding, but even if you're not you should still be able to work this in.
The first thing you need to do is create a header widget and add it to defaultLayout in Foundation.hs.
pageHeaderWidget :: Handler Widget
pageHeaderWidget = do
mauthId <- maybeAuthId
return $(widgetFile "header")
defaultLayout widget = do
pageHeader <- pageHeaderWidget >>= widgetToPageContent
-- ...
withUrlRenderer $(hamletFile "template/default-layout-wrapper.hamlet")
Then you need to create the corresponding html and style for your header:
File: header.hamlet
<header>
$maybe authId <- mauthId
Welcome #{show aid} - <a href=#{AuthR LogoutR}> Logout
$nothing
<a href=#{AuthR LoginR}> Login
File: header.lucius
header {
background-color: #007fff;
height: 50px;
}
Finally, you need to edit default-layout-wrapper.hamlet and add
^{pageHead pageHeader}
to the <head> tag just below ^{pageHead pc} (generated by the scaffolding); and replace
<header>
in the <body> with
^{pageBody pageHeader}
I have the following line which generates a form tag;
<%= form_for :stream, url: stream_path(#stream), method: :patch do |f| %>
It generates the following;
<form method="post" action="/streams/52b02d267e3be39d3da5aa609f1049d7" accept-charset="UTF-8">
If I change it to :put it still has it has post but if I write method: :get it will change it to get
Does anyone have any idea why it would be doing this and what I can do to prevent it?
Here is the output from rake routes;
Prefix Verb URI Pattern Controller#Action
streams GET /streams(.:format) streams#index
POST /streams(.:format) streams#create
new_stream GET /streams/new(.:format) streams#new
edit_stream GET /streams/:id/edit(.:format) streams#edit
stream GET /streams/:id(.:format) streams#show
PATCH /streams/:id(.:format) streams#update
PUT /streams/:id(.:format) streams#update
DELETE /streams/:id(.:format) streams#destroy
The background is this is a simple edit form, all I want it to do is his the update method of the controller.
Follow up
In my layout file I am bringing in csrf_meta_tags and my javascript_include_tag links to a file called "stream" which has the following
//= require jquery
//= require jquery_ujs
method: (:get|:post|:patch|:put|:delete)
from the documentation:
"in the options hash. If the verb is not GET or POST, which are natively supported by HTML forms, the form will be set to POST and a hidden input called _method will carry the intended verb for the server to interpret."
source: http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html
is //= require jquery_ujs in your application.js?
also make sure
<%= javascript_include_tag "application"%>
<%= csrf_meta_tag %>
are present in your layout file.
I'm running the developer's Django server while writing a simple view and it seems whenever I request a page, the console shows that there are 2 GETs for the same URL. What would cause this happen? I'm not using any redirects, so I don't see how a 2nd request would be made?
EDIT: It appears to be caused by the template. Changing to a blank html file for a template resolved the issue. The question is why? I have multiple {% if %} {% endif %} sections, with no elses. Could that be an issue?
It also could be Firefox following a WC3 directive under which it's supposed to dual load if certain tags come empty or broken, for example, a without a src="" etc. That being said, I saved off the rendered HTML on receipt and moved it into a static file, where I added the same headers as the real checkout and a small DB log of all accesses.
I just stumble upon this problem and fixed it removing my img wit src=""
Please confirm, if Django is redirecting after appending slash to your url. Its the property APPEND_SLASH in your settings.py controls that.
The second request is probably caused by a mis-configured asset link - a script, style or img tag which is empty or omits the initial / and is therefore re-requesting the page.
It could be your shortcut/favicon
Do you have link rel="shortcut icon" in your page template? Comment it out to see if it removes the second request
In my case : I have the same javascript code in 2 files : one in the base template and the same one in another template. As I use ajax to not reload all the page I got the call 2x, then 4x, and 8x, ...
The solution is the use the javascript code only in mybase.html
Hereafter my js code :
<script type="text/javascript">
// Code jQuery Ici
$(document).ready(function(){
// GET
$(".ajax_onglet_get").click(function(e){
var lien = $(this).attr('href');
$('#zone_travail').fadeOut('fast', function(){
$('#zone_travail').load(lien, function() {
$('#zone_travail').fadeIn('fast');
});
});
e.preventDefault()
});
});