Class 'HTML' not found - templating

I have required and installed "illuminate/html": "~5.0" like here: http://laravel.com/docs/5.0/upgrade and added it to the 'providers' and 'aliases' like there.
The problem is, I still get:
FatalErrorException in 65ad332c3ff984a4112203ba0538718c line 23:
Class 'HTML' not found
I have also tried to use Html; in the controller that 'makes' the view and in the view itself, but it did not help. Must I use the facade somewhere, or what could it be, that I am doing wrong?
I need this to use Html macros.
edit:
Seems to work now. I had to use Html in the view instead of HTML

The 5.0 docs are slightly misleading. If you are upgrading from a Laravel 4 app - you would be used to using HTML as the class.
So docs say to put this as your facade
'Html' => 'Illuminate\Html\HtmlFacade',
but if you want to continue to use HTML then it should be this
'HTML' => 'Illuminate\Html\HtmlFacade',

Related

Understanding the purpose of the underscore in grails templates

Working with grails templates and the render method isn't that hard.
I worked with it for a while now.
It's okay for me to deal with the 'Convention over Configuration'. And so it is with the needed underscore "_" at the beginning of the filename of a template .gsp file.
I'm not that experienced with programming in general, I'm doing an apprenticeship as a 'IT-specialist for application development' since 2,5 years now. So my background knowledge isn't that big yet.
But I'd now really like to understand what exactly the purpose of that underscore is.
How's grails dealing with files with a leading underscore in comparison to those without it?
String view='/path/to/file'
def model= [template:view,instance:bean]
render(view:view, model:model)
this tells that template is '/path/to/_file.gsp' when it renders the template bit
when it renders view it looks for '/path/to/file.gsp'
so when you do render view it looks for files without underscore
when you do render template it looks for those with underscore
above example does both to explain how it works
As others have already pointed out the underscore indicates that the file is a template. However, the question still remains "what's the purpose?"
The purpose of a template is to provide a way to render a reusable fragment of view code. This allows you to compose very complex views (e.g. think functional decomposition). Templates aren't decorated by the sitemesh layout. This is very important when doing partial page updates with AJAX (or similar technology).
The documentation actually explains templates quite well.

Using the lib folder for application parts in rails

there are some problems with Ruby on Rails I couldn't solve even spending hours and hours trying. I hope you guys can help me. The four questions are marked with Q1-Q4 at beginning of line.
I have an element in the view that I need more than once. For this reason there should be a separate module in the lib folder (so I can use it in an other project too).
What I need:
- A helper method that I can call automatically from any view.
- Since it requires more html stuff, I want to use an html file, which I render in the helper-method.
- Pass parameters to a javascript file.
- If the element is used, the JavaScript file must be included
- If the element is used, the CSS file must be included
Since it isn't easy to understand what I mean, I'll explain it again with a simple example (it's just an example, so don't think to much about its sence): Helper for creating a combo box with a view-helper or alternatively with a javascript method.
Clearly, I need
(html) - a text input field placed on top of a drop down box
(js) - a function that displays the selected item of the drop-down box in the text box.
(css) - the style of the text box positioned in front of the drop down.
(settings) - a settings file that initializes the element so that I can use it everywhere automatically.
The folder structure which I imagine:
lib
combo_box
combo_box_helper.rb
_combo_box.html.erb
combo_box.js
combo_box.css
At the combo_box-helper.rb I have 2 Methods:
combo_box_field(drop_down_content)
The method gives back a combobox using the partial. The array entries are available in the drop down box.
combo_box_js(drop_down_content)
The method must be called when a combo box is to be created using javascript. To make changes to the combobox only once, the element should also be created with the partial and passed to javascript.
Here appear the first problem:
Q1: At the first call (and only on the first call) of any method, it have to include the js and css file. What is the common way to do this?
Q2: How can I render a partial that is located in the lib folder and not in the app/view folder?
Q3: What is the common way to pass parameters to javascript?
My first try:
module ComboBoxHelper
def combo_box_field(drop_down_content)
output = check_first_call
output + render(:partial => 'combo_box', :locals => {:content => drop_down_content})
end
def
output = check_first_call
output + "<div class='hidden' data-combobox = '" + render(:partial => 'combo_box', :locals => {:content => drop_down_content}) + "'></div>"
end
def check_first_call
if #already_called
""
else
#already_called = true
javascript_include_tag("combo_box.js") + stylesheet_link_tag("combo_box.css")
end
end
end
Problems:
render-method doesn't work (it searches in app/view for the partial)
the call of check_first_call is ugly. especially as it returns a string.
the includes of javascript and css don't work (the files aren't in the asset pipeline)
The content of the .html.erb and .css files is self-explanatory.
Interesting part of the javascript file is my attempt to access parameters passed by Ruby on Rails:
$('div.hidden[data-combobox]').data("combobox")
If these problems are solved, only one thing is important:
How do I initialize the module correctly, so I use it automatically everywhere.
My first try:
I create a file at the folder config/initializers/init_combo_box with that code:
require_dependency 'combo_box/combo_box_helper'
ActiveSupport.on_load(:action_view) do
include ComboBoxHelper
end
Q4: Is this the common way? Do I have something to add to solve one of the above problems (for example the add the js- and css-files to the asset pipeline)?
Thanks for your help.

Displaying Twitter Handle Using ASP.NET MVC

This might be really simple question and I though the <text> tags were the answer but they do not seem to be working on my part.
I simply want to display #azamsharp in my asp.net mvc application.
<text> #azamsharp </text>
gives me the following error:
The name 'azamsharp' does not exist in the current context
##azamsharp
Razor see the # and thinks you're escaping into code, so it looks for a variable azamsharp. ## tells razor you want to print an # symbol, not escape into code.
Try this instead:
##azamsharp
That should work

Using T4MVC in real project

T4MVC is cool, but I have a couple of issues integrating it in my project, any help is really appriciated:
I've got such warnings for all my actions (I use SnippetsBaseController as base class for all my controller classes:
Warning 26 'Snippets.Controllers.ErrorController.Actions' hides inherited member 'Snippets.Controllers.Base.SnippetsBaseController.Actions'. Use the new keyword if hiding was intended. C:\projects_crisp-source_crisp\crisp-snippets\Snippets\T4MVC.cs 481 32 Snippets
Is it possible to have strongly typed names of custom Routes, for example, I have route defined like this:
routes.MapRoute(
"Feed",
"feed/",
MVC.Snippets.Rss()
);
Is it possible to replace:
<%= Url.RouteUrl("Feed") %>
with something like:
<%= Url.RouteUrl(MVC.Routes.Feed) %>
Having strongly typed links to static files is really cool, but I use <base /> in my pages, so I don't need any URL processing, can I redefine
T4MVCHelpers.ProcessVirtualPath without tweaking the T4MVC.tt itself?
T4MVC always generate links with uppercased controller and action names, for example:
/Snippets/Add instead of /snippets/add. Is it possible to generate them lowercase?
Can you change your base controller class to be abstract? I think that'll fix it.
See this post which discusses this: http://forums.asp.net/t/1535567.aspx
If you look in t4mvc.settings.t4, you'll see a ProcessVirtualPathDefault method that you can change without touching the main .tt file.
See http://forums.asp.net/t/1532057.aspx. There is suggested fix in there, though it has not yet been submitted (but you can try it).
David

Where should I place code which generates Excel spreadsheet?

I am using spreadsheet gem to generate native Excel file. This is not CSV, XML file. Ordinary Ruby code is used to create the file. The generated Excel file (kept in StringIO) is forwarded to a client using send_data method. I need send_data method because of its parameters like disposition.
The data for the Excel is retrieved in controller method just like for ordinary HTML, JS requests. However I placed the code to generate the spreadsheet in controller protected method. Not in a view as I should.
Is there an elegant solution to above problem compliant with MVC design pattern?
Update: There is no popular and accepted by all solution to above problem but at least I know all possible ideas.
The lib directory is meant as a place for code that isn't strictly part of the MVC structure, but will be needed by multiple models, views, or controllers. It can be brought in with a require when needed.
However, if you only need the code in a single controller, you'd be just as well off putting it into that controller's helper. That way it's auto-loaded and at your fingertips. Plus, it makes sense: it's code to help a specific controller.
Either way, don't leave it in your controller or try to wedge it into your view.
Create an excel library in your lib folder in which you include your xls generation routine as well as a method that overrides ActionController's render method.
In a model that should be rendered as xls implement a method called to_excel method which generates a hash that you can provide to your xls routine.
Doing it this way, you'll get something really "Railsy". In your controller you'll just call
render :xls => #model
i just did this today for my app hope this helps for an excel o/p ; never used any plugin
controller:
def export
pr = Program.find(session[:pr_id])
headers['Content-Type']="application/vnd.ms-excel"
headers['Content-Dispositon']='attachment;filename="report.xls"'
#voucherdatas = Voucherdata.find_all_by_pr_name(pr.pr_name)
end
view: export.html.erb
manager
"reports/voucherdatas", :object =>#voucherdatas %>
routes.rb
map.resources :reports ,:collection =>{:export =>:get}
whereever u want the link give
link_to "Export As Excel", export_reports_url, :popup=>true

Resources