Rails 4 fomatting with slim error - ruby-on-rails-4

i have this simple erb code that works perfectly, joint to my i18n.yml file. The idea is to get the client's edit.html.erb page, get the title of that page in my en.yml file and pass that title the #client.fullname variable. Like so:
<h1><%= t('client.edit.title'), :current_client => #client.fullname %></h1>
Now, i'm in the process of translating my erb files into slim. So the result of that line of code is
h1 = t('client.edit.title'), :current_client => #client.fullname
But it wouldnt pass the variable to the en.yml file. Instead, it throws this error:
/app/views/clients/edit.html.slim:1: syntax error, unexpected ',', expecting ')' ...tty2 = (t('client.edit.title'), :current_client => #client.f... ... ^
Would anyone know what i'm doing wrong here?

The hash parameter options should be passed within the method call parentheses, like so
h1 = t('client.edit.title', :current_client => #client.fullname)
Not sure why this would have worked in ERB, but it doesn't look correct as written.
You can also remove the parentheses altogether
h1 = t 'client.edit.title', :current_client => #client.fullname

Please try:
h1
= t('client.edit.title'), :current_client => #client.fullname

Related

RenderLink returns "Empty String " in Glass.Mapper

I'm trying to show a title of a news as a link
#using Glass.Mapper.Sc.Web.Mvc
#model MVC.com.Models.News
it works:#Model.Title<br/>
it dosen't work : #Html.Glass().RenderLink(x => x.Url,new {#class=""} ,true, Model.Title)
Anchor tag works fine but can not generate a link using RenderLink.
Meanwhile, is there any way I can eliminate #Html.Glass() helper from lines? I added Glass.Mapper.Sc.Web.Mvc to file Web.config but still have to wirte #Html.Glass() at the beginning of each command
You can eliminate #Html.Glass() this way:
#using Glass.Mapper.Sc.Web.Mvc
#RenderLink(Model, x => x.Link, new { #class = "btn" }, true,Model.Title)
i think you can do this which should eliminate #Html.Glass()
#inherits GlassView<News>
after that i think you should be able to do this.
#RenderLink(Model, x=>x.Url,new{#class=""},true)

Pass array from template to partial

My showAction() looks like this:
public function showAction() {
$form = $this->formRepository->findByUid($this->settings['form']);
$arguments = $this->request->getArguments();
$this->view->assignMultiple(
array(
'form' => $form,
'arguments' => $arguments
)
);
}
In the template of this action I try to give 'arguments' to all my partials:
<f:render partial="FormElement/{formElement.type}" arguments="{formElement:formElement, arguments:arguments}" />
The debug of {arguments} in the template shows me that everything is fine. If I debug the {arguments} inside the partials, it returns NULL. Even if I give all arguments to the partials (arguments="{_all}"), NULL will be returned by debugging {arguments} inside the partials.
Everything else works fine!
Your code looks fine to me. You might want to check your php.ini file for the following setting "max_input_nesting_level". Sometimes, if this parameter is set to a low value and your handling a complex object you run into this restriction. You might want to change it to 128 oder even 256. (Don't forget to restart your apache after changing your php.ini)

CakePHP reading Cookie with multiple dots

I am using CakePHP to develop a website and currently struggling with cookie.
The problem is that when I write cookie with multiple dots,like,
$this->Cookie->write("Figure.1.id",$figureId);
$this->Cookie->write("Figure.1.name",$figureName);`
and then read, cakePHP doesn't return nested array but it returns,
array(
'1.id' => '82',
'1.name' => '1'
)
I expected something like
array(
(int) 1 => array(
'id'=>'82',
'name'=>'1'
)
)
Actually I didn't see the result for the first time when I read after I write them. But from second time, result was like that. Do you know what is going on?
I'm afraid it doesn't look as if multiple dots are supported. If you look at the read() method of the CookieComponent (http://api.cakephp.org/2.4/source-class-CookieComponent.html#256-289), you see this:
277: if (strpos($key, '.') !== false) {
278: $names = explode('.', $key, 2);
279: $key = $names[0];
280: }
and that explode() method is being told to explode the name of your cookie into a maximum of two parts around the dot.
You might be best serializing the data you want to store before saving and then deserializing after reading as shown here: http://abakalidis.blogspot.co.uk/2011/11/cakephp-storing-multi-dimentional.html

How to match and return part of an HTML file in ASP

I'm looking to match a part of several HTML files that get passed into a loop in an ASP file and then return that part of the HTML files to include in my output. Here's my code so far:
<%for i=0 to uBound(fileIDs) ' fileIDs is an array of URLs
dim srcText, outText, url
Set ex = New RegExp
ex.Global = true
ex.IgnoreCase = true
ex.Pattern = "<section>[\S\s]+</section>" ' This finds the HTML I want
url = fileIDs(i)
Set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP")
xmlhttp.open "GET", url, false
xmlhttp.send ""
srcText = xmlhttp.responseText
outputText = ex.Execute(mediaSrcText) ' I expect this to be the HTML I want
Response.Write(outputText.Item(0).Value) ' This would then return the first instance
set xmlhttp = nothing
next %>
I've tested the regular expression on my files and it's matching the parts that I want it to.
when I run the page containing this code, I get an error:
Microsoft VBScript runtime error '800a01b6'
Object doesn't support this property or method
on the line with ex.Execute. I've also tried ex.Match, but got the same error. So I'm clearly missing the proper method for returning the match so I can write it out into the file. What is that method? Or am I approaching the problem from the wrong direction?
Thanks!
You need a Set when you're assigning outputText:
Set outputText = ex.Execute(mediaSrcText)
I should probably also say that you really shouldn't be using regular expressions to attempt to parse HTML, although I don't know enough about the context to offer more specific advice.

Drupal preprocess function and session

I set a session var at template preprocess function in a theme I use, but the first time I open the site I cant read the session var, if I refresh the page it works fine, anybody know what can be the problem??
This is the code I use in the preprocess function:
function m_preprocess(&$vars, $hook) {
$default_location = array(
'country_code' => 'ec',
'province_code' => 'p',
'province' => 'Pichincha',
'city' => 'Quito',
'city_path' => 'lugares/u/ec/p/*'
);
if (isset($_COOKIE['proximity_path'])) $default_location['proximity_path'] = $_COOKIE['proximity_path'];
$default_location['path'] = isset($_COOKIE['sort-by']) && $_COOKIE['sort-by']=='proximity'? $_COOKIE['proximity_path'] : $default_location['city_path'];
$_SESSION['location'] = $default_location;
}
A couple of things:
Try dsm($_SESSION); to see what is the var content when the site first load.
I don't know where you create $_COOKIE['proximity_path'], but it is not in the code you show.
Check for typos
The template pre-process function is called before node.tpl.php (that's why it is called pre-process) and that is why the value of the $_SESSION variable is not available in the template preprocess function.
Like you pointed out, it works after the first page load. This happens when only after $_SESSION variable is set in the node body (using the PHP filter)