rails 3.1, how to integrate JavaScript in View? - ruby-on-rails-3.1

I would like to know please, what is the proper way to enable/ disable an element at page ?
I have a view, but, I don't know the best way to do it ??
Is there a quick helper or gem that would access any element at page and set its HTML properties ?
Shall I put a function in a coffee file and call it from view ? how would I do so ??
Is there a good tutorial to see about integrating coffee or JavaScript with View using the new asset pipeline at Rails 3.1 ??

I found the solution ( for an href link )
in haml, it would be:
:javascript
$('#'+NEXT_PAGE_ID).attr('href', 'javascript: void(0)');
$('#'+NEXT_PAGE_ID).attr('style', 'color: #888888');
I've changed the color to dark gray to look as in-actve ..

Related

Change content view of Laravel layout without page refresh

I've been searching for an hour on how to nagivate within my Laravel website without refreshing the website (page layout), but I couldn't find a proper solution: one that not just loads the HTML, but actually replaces the content view within the layout.
This is my current dashboard:
So when clicking on a menu item within the blue area, I want the red content area to change without page refresh. What would be a scalable solution for this? I'm trying to follow the DRY (Don't repeat yourself) principle as much as possible.
Oh, please don't mark this topic as a clone of other topics as I've seen most of them but without proper solution. Hope anyone can help me out.
Changing a view without page load means we need to use the ajax techology. Vuejs is a frontend frameework the allows us to acomplish that easily with its axios library
I believe you can get this done by using jQuery load function -
$(function () {
$("#menu_option_a").on("click", function () {
$("#dashboard").load("View1.html");
});
$("#menu_option_b").on("click", function () {
$("#dashboard").load("View2.html");
});
});

Joomla display view not displaying site template

I am trying to load a view from my controller using the follow code but I only get a raw HTML view and does not show the site's template.
$view = $this->getView( 'download', 'html' );
$view->display();
Can some help me in what I am doing wrong to display the site's template.
I also tried a redirect but that did not work either
$this->redirect(JRoute::_('index.php?option=com_atdwcsv&view=download'), false);
Edit: I figured out what was wrong with the redirect. Code I needed was
$this->setRedirect('index.php?option=com_atdwcsv&view=download');
$this->redirect();
I could be wrong, but I don't think you need to use the display() method on the view, I think you need to use $this->display(); instead.

How can integrate html template in codeigniter

I'm new to codeigniter. please tell me how can I integrate or install a html theme/template in codeigniter ? (my css folder path=news/css and application folder path=news/application where news is my main folder)
-thanks.
This is a very simple, very powerful way to do templates in codeigniter that is also very flexible.
http://news.dice.com/2013/02/18/how-to-build-a-to-do-app-with-codeigniter/
ignore the title, most of the lesson is about setting up templates in CI.
Note that i was first exposed to this method from a jeffrey way CI tutorial on net.tutsplus.com
All of them are worth checking out: http://net.tutsplus.com/sessions/codeigniter-from-scratch/
edit -- ok this is good enough addition to post. So in the tutorial, on the template.php page, you will see
$this->load->view($maincontent);
which is cool. but this is much better:
// load your header views
$templatefolder = 'beta/';
if(isset($content01))
$this->load->view($templatefolder.$content01);
if(isset($content02))
$this->load->view($templatefolder.$content02);
if(isset($content03))
$this->load->view($templatefolder.$content03);
// load your footer views
so instead of calling the view "maincontent", i've put in references to $content1, $content2, etc. Because we are doing if isset none of them are required. that way you can easily send more then one view file to the template. Or none at all if you are just showing a message, etc. Also notice that we have $templatefolder - that way you can easily reuse the template file for other site templates, even with the same content.
in your controller (similar to tutorial) it would be
$data['content01'] = 'codeigniterrawks';
$data['content02'] = 'mypetlion';
// beta template
$this->load->view( 'template_beta', $data );
note how easy it is if i want to bring in those same view files into a different template
$data['content01'] = 'codeigniterrawks';
$data['content02'] = 'mypetlion';
// alpha template
$this->load->view( 'template_alpha', $data );
I ran into this exact question about a week ago, this guide really helped me:
http://net.tutsplus.com/tutorials/php/an-introduction-to-views-templating-in-codeigniter/
To do the CSS url's, I added "uri" to my libraries in config/autoload.php (so it looks like this:
$autoload['libraries'] = array('uri', 'database');)
" type="text/css" media="screen" />
the base_url function automatically return whatever the base url of your site is, ie
http://localhost/news/
with the argument appended to the end.
The reason behind this is that if/when you ever need to migrate servers, you just change the base_url in the config file and it automatically updates across all of your templates and sources.
Try this,
I'm using this and it's very powerful.
https://github.com/philsturgeon/codeigniter-template

Rendering a local template with Sammy.js

I am using sammy for a web application that needs to render templates stored inline in the page. I am using a script tag to contain the markup, which is haml.
Is there a good, idiomatic way to render templates that are not loaded via ajax request? I have a solution, but I am not happy with it. $('#start_haml') is the script element containing the markup and $('#sammy_main') is the container to render into.
app.get '#/', (context) ->
context.load($('#start_haml')).then((data) ->
context.interpolate(data, {helpers: view_helpers})
).replace('#sammy_main')
Thanks to Aaron Quint for answering me on the Sammy.js mailing list
The answer is simple, but worth leaving here since it is not mentioned in the documentation.
context.render($('#start_haml'), {helpers: view_helpers})
.replace '#sammy_main'
NB. The second parameter to render() is the view data.
For me, this worked:
this.use('Template', "[object HTMLScriptElement]"); // If not view data are not rendered
[...]
var template = $('#tmpInmuebleDetalle')[0];
this.partial(template);

In a View page within MVC, what is the preferred way to deal with empty variables

When using the MVC design pattern I usually try to make my view files as simple as possible.
Therefore in my View I try not to have lots of code like this:
if page title exists
display page title
else
display 'default page title'
end if
Instead, in my Controller I might use code like this:
if no page title is specified
page title = 'default page title'
end if
load the view (pass page title as a parameter)
Is this the best way to tackle this issue?
Keeping this if-else condition in the controller level is a better idea than moving into views. (if you can otherwise it's alright)
It will make your views look good !!!!

Resources