I have a problem in solving this.
= link_to "Bounced", bounced_email_path(#email)
Bounces
%span
= #email.bounces_count
I want the Bounces, span and other lines within the link tag.
The above code ends up in an error:
syntax error, unexpected kENSURE, expecting $end".
To use the block form of link_to, you must remove the body parameter ("Bounced") and use the do keyword to start the block:
= link_to bounced_email_path(#email) do
Bounces
%span
= #email.bounces_count
Related
My HAML reads:
%table.screenshots
%thead
%trow
%td{:colspan => 12} Screenshots for #{element.name}
%tbody
- screenshots.each do |set|
%tr
- set[1].each do |shot|
- if shot == :blank_cell
%td{:colspan => set[0]}.twelfth
- else
%td{:colspan => set[0]}.twelfth
= image_tag(shot[1]) # <= ERROR APPEARS HERE
- if #redacted
%h1.blur
%span Image blurred in
%br
%span demo report only
%p #{shot[0]}
There are no invisible spaces or tabs after .twelfth.
Why, then, do I get this error?
Illegal nesting: content can't be both given on the same line as %td and nested within it.
BTW, I get the same exception when I run:
haml --debug print.html.haml
The class and id identifiers (. and #) must come after the tag name, and before any attribute hash.
In your code the problem is the line:
%td{:colspan => set[0]}.twelfth
This is interpreted as a td element with a colspan attribute, containing the content .twelfth, which would look like this when rendered, if it were by itself:
<td colspan='7'>.twelfth</td>
However this line also has content nested below, which Haml doesn’t allow.
You can fix this by using an explicit class entry in the attribute hash as you have in your answer, or by moving the .twelth class specifier in front of the attribute hash, like this:
%th.twelfth{:colspan => set[0]}
Fixed it by changing the offending line to:
%td{:colspan => set[0], :class => "twelfth"}
Looks like there's a bug in the HAML interpreter
I am new to Haml and am trying to simply place a span tag within an anchor link like so:
.text Here is some copy.
= link_to 'Visit website', 'https://websitelink.com/', class: 'link'
%span
This is throwing an error, "syntax error, unexpected keyword_ensure, expecting $end"
How Do I perform this simple task?
Rails’ link_to helper accepts either the link text as a parameter or as the result of a block.
In this case you probably want something like this:
= link_to 'https://websitelink.com/', class: 'link' do
%span Visit website
Note the do indicating a block, and that there are only two parameters to the method, the “Visit Website” text has been moved into the block.
This renders:
<a class="link" href="https://websitelink.com/"><span>Visit website</span>
</a>
I have a form that needs to submit a .csv file to the server and then append the words in it to a textarea in my page. I am using Remotipart to upload the .csv using AJAX but I cannot get the javascript in the server response to execute. Here are the relevant parts of my code:
The Form:
=form_tag(upload_canvas_words_admin_page_widget_widget_instance_path(widget.page, widget),:method=>'post',:remote=>true,:multipart=>true,:class=>"upload_words_csv") do
= label_tag "Upload File"
= file_field_tag "file"
= submit_tag "Upload"
The Controller:
def upload_canvas_words
#csv_text = params[:file].read
end
The .js.haml file:
= remotipart_response do
- if remotipart_submitted?
alert('#{#csv_text}');
alert('!');
- else
alert('WHYYYYY?');
When I look at the response I see the javascript being wrapped in a bunch of html, which I assume has something to do with the iFrame transport. But the javascript never actually executes.
Refer this issue. And try to follow the solution given here.
https://github.com/JangoSteve/remotipart/issues/89
So what happens is that reponse arrives to the browser with html entity (like ") inside the textarea. When the js code for evaluation is extracted the html entities are replaced by theirs respective characters (like " to ').
That's a characteristic of a textarea. So it doesn't get executed
Adding data: {type: :script} to the form should be the fix
If i have the following javascript code
var myVar = 0;
function setNewValforVar(newValue){
myVar = newValue;
}
and i'm calling setNewValforVar function n times
so when I click on a link it'd send myVar value to the controller action in a remote link like
<%=link_to "My Link",{:action=>"myAction"},:data=>''sval='+myVar',:remote=>true%>
I Rails 2.3.x I'd do this with
<%=link_to_remote "My Link",:url=>{:action=>"myAction"},:with=>"'sval='+myVar"%>
and i was getting this on the controller's action with
params["myVar"]
how do I do this on Rails 3 with the link_to helper?
Rails 3 no longer supports this behavior. You will have to either create a form to submit the value, or modify the href of the link to include the value in the query string.
I found some solution that use callbacks. Link must be marked in some way, for example by adding the id:
<%=link_to "My Link", {:action=>"myAction"}, :remote=>true, :id => "mylink" %>
There is an example for prototype_ujs: the parameter is simply appended to the request's URL (the code is a bit simplified I assume that some parameters already exist).
<%= javascript_tag("document.on('ajax:create', 'a#mylink',
function(event) { event.memo.request.url += '&sval=' + myVar; })") %>
Some advantage of this (ugly a bit) solution is the possibility of using one function for a particular class of links instead of the indicated id.
I have a button in aspx page, I want to set its Enabled property using code behind variable.
I did it like this:
'>
It gives me error message: Cannot create an object of type 'System.Boolean' from its string representation '<%=this.AllowDelete %>' for the 'Enabled' property.
I changed it to Enabled = <%=this.AllowDelete %>,
It gives me error message: Server tags cannot contain <% ... %> constructs.
I tested <%=this.AllowDelete %> in other place of page, it shows 'false' correctly.
How to set it for enabled property correctly?
It's such a simple question but stuck me for a while. Any help is appreciated. Thanks you!
I know this doesn't exactly answer your question, but are you able to set the button's enabled property in Page_Load function in your code-behind?
Page_Load(...)
{
if(this.AllowDelete)
btn.Enabled = true;
...