Nested if is not working in eco template engine - coffeescript

I was trying use nested if in eco template. Here is my code
<% for document in #getCollection('posts').toJSON()[#document.page.startIdx...#document.page.endIdx]: %>
<% if true %>
<p> <%= new Date(document.date.toDateString()).getTime() <= new Date(new Date().toDateString()).getTime() %> </p>
<div class='row-fluid'>
<div class='span12 blogShadow'>
<div class="row-fluid">
<div class='span12 archiverow'>
<span>(<%= document.date.toDateString() %>) => </span>
<span>
<%= document.title %>
</span>
</div>
</div>
<div class="row-fluid archiverow">
<% if document.img:%>
<img class="span1" src="<%= document.img %>" width=100 height=100 />
<span class="span11"><%= document.description %></span>
<% else: %>
<span class="span12"><%= document.description %></span>
<% end %>
</div>
</div>
</div>
<% end %>
<br/>
<br/>
<% end %>
if I remove first if with its corresponding end statement things working fine, but if I put that it is giving parsing error with message unexpected dedent.
for the else statement down there
<% else: %>
<span class="span12"><%= document.description %></span>
<% end %>
I am new to eco and I don't understand the message. Is this kind of nested if is possible and if not what is the work around for this.
As, I am using docpad and eco I am using as template engine.
Please let me know if any further details is required.

I able to solve the issue by following code. I was missing : to evaluate expression.
<% for document in #getCollection('posts').toJSON()[#document.page.startIdx...#document.page.endIdx]: %>
<% if (new Date(document.date.toDateString()).getTime() <= new Date(new Date().toDateString()).getTime()): %>
<div class='row-fluid'>
<div class='span12 blogShadow'>
<div class="row-fluid">
<div class='span12 archiverow'>
<span>(<%= document.date.toDateString() %>) => </span>
<span>
<%= document.title %>
</span>
</div>
</div>
<div class="row-fluid archiverow">
<% if document.img:%>
<img class="span1" src="<%= document.img %>" width=100 height=100 />
<span class="span11"><%= document.description %></span>
<% else: %>
<span class="span12"><%= document.description %></span>
<% end %>
</div>
</div>
</div>
<% end %>
<% end %>
both if is working without any issue.

Related

Ruby on Rails. How to combine a search form with bootstrap style?

How to combine this search form
<%= form_tag index_path, :method => 'get' do %>
<%= text_field_tag :search, params[:search]%>
<%= submit_tag "search", :title => nil %>
<% end %>
with this bootstrap style
<div class="row">
<div class="input-group">
<input type="text" class="form-control" placeholder="Search for...">
<span class="input-group-btn">
<button class="btn btn-default" type="button">search</button>
</span>
</div>
</div>
You can add any class you like to any Rails form tag. You just need to be careful that your method call matches one of the valid call signatures for the tag helper. For instance, the API for the form tag is documented here.
Here is my take on combining the above. This may need some tuning:
<div class="row">
<%= form_tag index_path, :method => 'get', class: 'input-group' do %>
<%= text_field_tag :search, params[:search], class: 'form-control', placeholder: 'Search for...' %>
<span class="input-group-btn">
<%= submit_tag "search", class: "btn btn-default" %>
</span>
<% end %>
</div>

Inline-block for search form in Bootstrap 3

I have the following navbar in my Rails app. I can't figure out why the search button, which is an image, won't stay inline to the right of the search form. I'm sure there is a some parent CSS that is preventing it, but I can figure it out.
<nav class="navbar navbar-static-top navbar-default" role="navigation">
<div class="container">
<div class="navbar-header">
<%= link_to "theTens", root_path, class: "navbar-brand" %>
</div>
<div class="collapse navbar-collapse navbar-ex1-collapse">
<ul class="nav navbar-nav navbar-left">
<li>
<%= link_to 'theReviewers', reviewers_path %>
</li>
<li>
<%= link_to 'theComments', comments_board_path %>
</li>
<li>
<%= link_to 'theStats', stats_path %>
</li>
<li>
<form action="/pins" class="form-inline col-xs-12" method="get">
<input id="search" type="text" name="search" class="form-control" placeholder="Search">
<%= image_submit_tag("search.png", :name => nil) %>
</form>
</li>
</ul>
<div class="collapse navbar-collapse navbar-ex1-collapse">
<ul class="nav navbar-nav navbar-right">
<% if user_signed_in? %>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown"> theMenu
<span class="caret"></span>
</a>
<ul class="dropdown-menu">
<li class="dropdown-toggle"><%= link_to 'Add +', new_pin_path %></li>
<li><%= link_to 'Edit Profile', edit_user_registration_path %></li>
<li><%= link_to 'Logout', destroy_user_session_path, method: :delete %></li>
</ul>
<li><%= link_to (image_tag current_user.image(:small), class: "smallpic"), current_user %></li>
<% else %>
<li><%= link_to 'Login', new_user_session_path %></li>
<% end %>
</ul>
</div>
</div>

docpad plugin-tagging Why lists all the tags?

Why lists all the tags?
I use:
<div class="tags">
<ul>
<% for tag, item of #getTagCloud(): %>
<li><a class="tag_item" href="<%= item.url %>" data-tag-count="<%= item.count %>" data-tag-weight="<%= item.weight %>"><%= item.tag %> (<%= item.count %>)</a></li>
<% end %>
</ul>
</div>
How to display a specific page tags?
<div class="tags">
<ul>
<% for tag in #document.tags: %>
<li><a class="tag_item" href="<%= #getTagUrl(tag) %>"><%= tag %></a></li>
<% end %>
</ul>
</div>

How to set a file_upload control for a field in rails_admin?

I'm new to rails and I recently discovered rails_admin.
How to set a file_upload control for a field in rails_admin?
If you are using the Carrierwave gem for your file uploads you can do something like this
https://gist.github.com/884835 or in erb if you prefer that:
<%= label_tag "#{field.abstract_model.to_param}_#{field.name}", field.label %>
<div class="input">
<% image = field.bindings[:object].send(field.name) %>
<% if image.path %>
<div class="row">
<% default_version = image.versions[:main] %>
<%= image_tag default_version && default_version.url || image.url %>
<br />
<%= form.check_box "remove_#{field.name}" %>
<%= form.label "remove_#{field.name}", "Remove existing #{field.label.downcase}", :class => "inline" %>
</div>
<% end %>
<div class="row">
<%= form.file_field field.name, :class => "fileUploadField #{field.has_errors? ? "errorField" : nil}" %>
<%= form.hidden_field "#{field.name}_cache" %>
</div>
</div>

MVC2 Entity Framework - Update Model

First of all, am I the only developer on the planet that is attempting to use MVC with VB? I have searched tons of forums and read many posts and everyone that asks a question gives an example in C#. Anyway, now that I've got that out of the way, I've got a simple database table (User) with some columns (UserId, Username, FirstName, LastName). I am using the entity framework and on my edit view, I'm changing a value (Username) and clicking Save. In my Edit http post, I tell it to return to the Index and the value was not saved. Although, in my constructor for the http post, I return the object and it shows the new value...but that value doesn't make it to the db...any help?
My Controller:
Function Edit(ByVal ID As Guid) As ActionResult
'get the user
Dim usr = (From u In db.Users
Where u.UserId = ID
Select u).Single
Return View(usr)
End Function
<HttpPost()> _
Function Edit(ByVal ID As Guid, ByVal usrInfo As User, ByVal formValues As FormCollection) As ActionResult
' Dim usr As User = db.Users.Single(Function(u) u.UserId = ID)
If ModelState.IsValid Then
TryUpdateModel(usrInfo, "User")
Return RedirectToAction("Index")
Else
Return View(usrInfo)
End If
End Function
My view:
<h2>Edit</h2>
<%-- The following line works around an ASP.NET compiler warning --%>
<%: ""%>
<% Using Html.BeginForm() %>
<%: Html.ValidationSummary(True) %>
<fieldset>
<legend>Fields</legend>
<div class="editor-label">
<%: Html.LabelFor(Function(model) model.UserId) %>
</div>
<div class="editor-field">
<%: Html.TextBoxFor(Function(model) model.UserId) %>
<%: Html.ValidationMessageFor(Function(model) model.UserId) %>
</div>
<div class="editor-label">
<%: Html.LabelFor(Function(model) model.Username) %>
</div>
<div class="editor-field">
<%: Html.TextBoxFor(Function(model) model.Username) %>
<%: Html.ValidationMessageFor(Function(model) model.Username) %>
</div>
<div class="editor-label">
<%: Html.LabelFor(Function(model) model.FirstName) %>
</div>
<div class="editor-field">
<%: Html.TextBoxFor(Function(model) model.FirstName) %>
<%: Html.ValidationMessageFor(Function(model) model.FirstName) %>
</div>
<div class="editor-label">
<%: Html.LabelFor(Function(model) model.LastName) %>
</div>
<div class="editor-field">
<%: Html.TextBoxFor(Function(model) model.LastName) %>
<%: Html.ValidationMessageFor(Function(model) model.LastName) %>
</div>
<div class="editor-label">
<%: Html.LabelFor(Function(model) model.CreatedDate) %>
</div>
<div class="editor-field">
<%: Html.TextBoxFor(Function(model) model.CreatedDate, String.Format("{0:g}", Model.CreatedDate)) %>
<%: Html.ValidationMessageFor(Function(model) model.CreatedDate) %>
</div>
<div class="editor-label">
<%: Html.LabelFor(Function(model) model.CreatedBy) %>
</div>
<div class="editor-field">
<%: Html.TextBoxFor(Function(model) model.CreatedBy) %>
<%: Html.ValidationMessageFor(Function(model) model.CreatedBy) %>
</div>
<div class="editor-label">
<%: Html.LabelFor(Function(model) model.LastLogin) %>
</div>
<div class="editor-field">
<%: Html.TextBoxFor(Function(model) model.LastLogin, String.Format("{0:g}", Model.LastLogin)) %>
<%: Html.ValidationMessageFor(Function(model) model.LastLogin) %>
</div>
<p>
<input type="submit" value="Save" />
</p>
</fieldset>
<% End Using %>
<div>
<%: Html.ActionLink("Back to List", "Index") %>
</div>
Ok, so, aparently I AM the only VB developer using MVC. Anyway, I found the answer. It was in one of the beginner tutorials for MVC on the ASP.Net Site (Found Here). The answer was to change my Edit function (HttpPost) so that it utilizes the formvalues that were posted:
<HttpPost()> _
Function Edit(ByVal id As Guid, ByVal collection As FormCollection) As ActionResult
Dim rest = (From r In db.Restaurants
Where r.RestaurantId = id
Select r).Single()
Try
TryUpdateModel(rest, collection.ToValueProvider())
db.SaveChanges()
Return RedirectToAction("Index")
Catch
Return View(rest)
End Try
End Function