Showing check box label with single quotes - ruby

Not able to show jQuery mobile check box with values like aa''a#a.com
#contact_info = [{:source_id=>40021, :object=>"148302514605161.2", :account_number=>"332950", :contact_type=>"E", :contact_value=>"aa''a#a.com", :sequence=>"1"}, {:source_id=>40021, :object=>"148302514605162.2", :account_number=>"332950", :contact_type=>"E", :contact_value=>"asdf#asd.org", :sequence=>"2"}, {:source_id=>40021, :object=>"148302514605163.2", :account_number=>"332950", :contact_type=>"E", :contact_value=>"dog#g.com", :sequence=>"3"}, {:source_id=>40021, :object=>"148302514605164.2", :account_number=>"332950", :contact_type=>"E", :contact_value=>"gh'g#ff.bn", :sequence=>"4"}, {:source_id=>40021, :object=>"148302514605165.2", :account_number=>"332950", :contact_type=>"F", :contact_value=>"2579525795", :sequence=>"5"}]
In .erb file
<table id="previous_email_fax_list">
<% if #contact_info. size > 0 %>
<% #contact_info.each do |contact|%>
<tr>
<td style="border:1px solid black;">
<div class="email_fax_check">
<input type="checkbox" name="<%= contact.contact_value %>" id="<%= contact.contact_value %>" class="custom" />
<label for="<%= contact.contact_value %>"><br/></label>
</div>
<div class="email_fax_label">
<% if contact.contact_type == "E" %>
<%= contact.contact_value %>
<% elsif contact.contact_type == "F" %>
<%= number_to_fax(contact.contact_value) %>
<% end %>
</div>
</td>
</tr>
<% end %>
<% else %>
<tr>
<td align='center'>
No email addresses or fax numbers found for this account
</td>
</tr>
<% end %>
</table>
I am getting Error: Syntax error, unrecognized expression: for='gh'g#ff.bn']

I copied this code:
<input type="checkbox" name="<%= contact.contact_value %>" id="<%= contact.contact_value %>" class="custom" />
<label for="<%= contact.contact_value %>"><br/></label>
and added it to an existing app view, adding a variable, removing contact. and removing all of the double quotes to make a test:
<% contact_value = "'gh'g#ff.bn'" %>
<input type="checkbox" name=<%= contact_value %> id=<%= contact_value %> class="custom" />
<label for=<%= contact_value %>><br/><%= contact_value %></label>
I get:
without any errors. Give it a try without any quotes around the <%= contact.contact_value %> in the view code.

Related

Spree: Deface getting error NameError in Spree::Home#index

I'm trying to change the look of the front page where the items are listed but I'm getting an error. Am I using deface correctly to change it? Its telling me that <%= link_to small_image(product, itemprop: "image"), url, itemprop: 'url' %> is giving me errors, if I removed then there are no pictures. What do I do?
update_products.rb
Deface::Override.new(:virtual_path =>"spree/shared/_products",
:name => "change site",
:replace =>"#products",
:text => '
<%
paginated_products = #searcher.retrieve_products if params.key?(:keywords)
paginated_products ||= products
%>
<% content_for :head do %>
<% if paginated_products.respond_to?(:num_pages) %>
<%= rel_next_prev_link_tags paginated_products %>
<% end %>
<% end %>
<div data-hook="products_search_results_heading">
<% if products.empty? %>
<div data-hook="products_search_results_heading_no_results_found">
<%= Spree.t(:no_products_found) %>
</div>
<% elsif params.key?(:keywords) %>
<div data-hook="products_search_results_heading_results_found">
<h6 class="search-results-title"><%= Spree.t(:search_results, keywords: h(params[:keywords])) %></h6>
</div>
<% end %>
</div>
<% if products.any? %>
<div id="products" class="row" data-hook>
<% products.each do |product| %>
<% url = spree.product_url(product, taxon_id: #taxon.try(:id)) %>
<div id="product_<%= product.id %>" class="col-md-3 col-sm-6 product-list-item" data-hook="products_list_item" itemscope itemtype="https://schema.org/Product">
<div class="panel panel-default">
<% cache(#taxon.present? ? [I18n.locale, current_currency, #taxon, product] : [I18n.locale, current_currency, product]) do %>
<div class="panel-body text-center product-body">
<br/>
<%= link_to small_image(product, itemprop: "image"), url, itemprop: 'url' %>
</div>
<div class="panel-footer text-center">
<span itemprop="offers" itemscope itemtype="https://schema.org/Offer">
<span class="price selling lead" itemprop="price"><%= display_price(product) %></span>
</span>
</div>
<% end %>
</div>
</div>
<% end %>
<% reset_cycle("classes") %>
</div>
<% end %>
<% if paginated_products.respond_to?(:num_pages) %>
<% end %>
')
one small quote issue for url <%= link_to small_image(product, itemprop: "image"), url, itemprop: "url" %> check this code :-
Deface::Override.new(:virtual_path =>"spree/shared/_products",
:name => "change site",
:replace =>"#products",
:text => '
<%
paginated_products = #searcher.retrieve_products if params.key?(:keywords)
paginated_products ||= products
%>
<% content_for :head do %>
<% if paginated_products.respond_to?(:num_pages) %>
<%= rel_next_prev_link_tags paginated_products %>
<% end %>
<% end %>
<div data-hook="products_search_results_heading">
<% if products.empty? %>
<div data-hook="products_search_results_heading_no_results_found">
<%= Spree.t(:no_products_found) %>
</div>
<% elsif params.key?(:keywords) %>
<div data-hook="products_search_results_heading_results_found">
<h6 class="search-results-title"><%= Spree.t(:search_results, keywords: h(params[:keywords])) %></h6>
</div>
<% end %>
</div>
<% if products.any? %>
<div id="products" class="row" data-hook>
<% products.each do |product| %>
<% url = spree.product_url(product, taxon_id: #taxon.try(:id)) %>
<div id="product_<%= product.id %>" class="col-md-3 col-sm-6 product-list-item" data-hook="products_list_item" itemscope itemtype="https://schema.org/Product">
<div class="panel panel-default">
<% cache(#taxon.present? ? [I18n.locale, current_currency, #taxon, product] : [I18n.locale, current_currency, product]) do %>
<div class="panel-body text-center product-body">
<br/>
<%= link_to small_image(product, itemprop: "image"), url, itemprop: "url" %>
</div>
<div class="panel-footer text-center">
<span itemprop="offers" itemscope itemtype="https://schema.org/Offer">
<span class="price selling lead" itemprop="price"><%= display_price(product) %></span>
</span>
</div>
<% end %>
</div>
</div>
<% end %>
<% reset_cycle("classes") %>
</div>
<% end %>
<% if paginated_products.respond_to?(:num_pages) %>
<% end %>
')

Values are not showing using Rails 3

I want to display data inside text field and those values will be fetched dynamically.But i am not getting any value(only blank filed is coming) when show action is executing.
Please check mu code given below.
Views/posts/show.html.erb
<p id="notice"><%= notice %></p>
<p>
<b>Name:</b>
<input type="text",value="<%= #post.name %>">
</p>
<p>
<b>Title:</b>
<input type="text",value="<%= #post.title %>">
</p>
<p>
<b>Content:</b>
<input type="text",value="<%= #post.content %>">
</p>
<%= link_to 'Edit', edit_post_path(#post) %> |
<%= link_to 'Back', posts_path %>
Please help me to resolve this issue.
Replace the value Property by removing quotes as:
<input type="text",value=<%= #post.content %>>

Template missing error in Rails 3

Hi i am facing the following error while trying to create a user using Rails 3.
Error:
Template is missing
Missing template admins/index, application/index with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :coffee]}. Searched in: * "C:/Site/swargadwar_admin/app/views"
Please check my below code and try to help me to resolve this error.
views/homes/index.html
<div class="container">
<div style="text-align:center;"><img src="/assets/admin.png" style="width:100px; height:120px; " /></div>
<div class="text-div" style="text-align:center;">Swargadwar, Puri Municipality,govt of odisha</div>
<section>
<div id="container_demo" >
<!-- hidden anchor to stop jump http://www.css3create.com/Astuce-Empecher-le-scroll-avec-l-utilisation-de-target#wrap4 -->
<a class="hiddenanchor" id="toregister"></a>
<a class="hiddenanchor" id="tologin"></a>
<div id="wrapper">
<div id="login" class="animate form">
<form action="mysuperscript.php" autocomplete="on">
<h1>Log in</h1>
<p>
<label for="username" class="uname" data-icon="u" > Your email or username </label>
<input id="username" name="username" required type="text" placeholder="myusername or mymail#mail.com"/>
</p>
<p>
<label for="password" class="youpasswd" data-icon="p"> Your password </label>
<input id="password" name="password" required type="password" placeholder="eg. X8df!90EO" />
</p>
<p class="keeplogin">
<input type="checkbox" name="loginkeeping" id="loginkeeping" value="loginkeeping" />
<label for="loginkeeping">Keep me logged in</label>
</p>
<p class="login button">
<input type="submit" value="Login" />
</p>
<p class="change_link">
Not a member yet ?
Join us
</p>
</form>
</div>
<div id="register" class="animate form">
<%= form_for :admins,:url => {:action => 'create_registration',:controller => "admins" } do |f| %>
<h1> Sign up </h1>
<p>
<label for="usernamesignup" class="uname" data-icon="u">Your username</label>
<%= f.text_field :user_name,placeholder:"mysuperusername690",:id => "usernamesignup" %>
</p>
<p>
<label for="emailsignup" class="youmail" data-icon="e" > Your email</label>
<%= f.email_field :email,placeholder:"mysupermail#mail.com",:id => "emailsignup" %>
</p>
<p>
<label for="passwordsignup" class="youpasswd" data-icon="p">Your password </label>
<%= f.password_field :password,placeholder:"eg. X8df!90EO",:id => "passwordsignup" %>
</p>
<p>
<label for="passwordsignup_confirm" class="youpasswd" data-icon="p">Please confirm your password </label>
<%= f.password_field :password_confirmation,placeholder:"eg. X8df!90EO",:id => "passwordsignup" %>
</p>
<p>
<label for="usernamesignup" class="uname" data-icon="u">Add Image</label>
<%= f.file_field :picture %>
</p>
<p class="signin button">
<%= f.submit "Sign Up"%>
</p>
<p class="change_link">
Already a member ?
Go and log in
</p>
<% end %>
</div>
<div class="error-div">
<% if #admin.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(#admin.errors.count, "error") %> prohibited this post from being saved:</h2>
<ul>
<% #admin.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
</div>
</div>
</div>
</section>
</div>
controller/admins_controller.rb
class AdminsController < ApplicationController
def create_registration
#admin=Admin.new(params[:admin])
if #admin.save
flash[:notice]="User has created successfully"
flash[:color]="valid"
redirect_to :action => "index" , :controller => "homes"
else
flash[:alert]="User could not created"
flash[:color]="invalid"
render 'index', :controller => "homes"
end
end
end
routes.rb
SwargadwarAdmin::Application.routes.draw do
root :to => "homes#index"
get "homes/index" => "homes#index"
post "admins/create_registration" => "admins#create_registration"
end
controller/homes_controller.rb
class HomesController < ApplicationController
def index
#admin=Admin.new
end
end
Actually i was trying by insert wrong data for checking validation and got this error at this line "render 'index',:controller => 'homes'".Please help me.

convert foreach-loop to for-loop for Viewdata["terr"] which is list of objects

I have a list of checkbox like:
<% foreach (var tobj in (ViewData["terr"] as List<Location>))
{ %>
<input type="checkbox" name="terr" id="<%: tobj.Location_Id %>" value="<%: tobj.Location_Id %>" disabled="disabled"/>
<span id="<%: tobj.Location_Name %>"> <%: tobj.Location_Name %> </span>
<br />
<% } %>
But I want to display 3 or 4 checkbox in one row. and for that I need to conver foreach to for loop. I am not able to achieve this. Hope anyone can help me in this.
Im not sure why you cannot accomplish what you need in the foreach loop though. If you updated your question with a bit more info we could probably help you debug the initial foreach loop. Also if your using MVC 3 i recommend the Razor view engine, the syntax is a lot nicer.
The for loop equivalent:
<% { var locations = (List<Location>)ViewData["terr"] } %>
<% for (int i = 0; i < locations.Count(); i++)
{ %>
<input type="checkbox" name="terr" id="<%: locations[i].Location_Id %>" value="<%: locations[i].Location_Id %>" disabled="disabled"/>
<span id="<%: locations[i].Location_Name %>"> <%: locations[i].Location_Name %> </span>
<br />
<% } %>

Issue in kaminari ajax pagination

Am using kaminari ajax pagination in my project. It is working fine, But contents are displaying number of pages times in the page. For example if number of items per pages is 7, then it is displaying 7 times the same content. What am doing is
In product_details controller
def index
#products=ProductDetail.where("department_id = ? and category_id = ?",1, 1).page(params[:page]).per(15)
end
In product_details/index.html.erb
<div id="product_details">
<%= render #products %>
</div>
<div id="paginator">
<%= paginate #products, :remote=>true %>
</div>
In product_details/index.js.erb
$('#product_details').html('<%= escape_javascript render (#products) %>');
$('#paginator').html('<%= escape_javascript(paginate(#products, :remote=>true).to_s)%>');
In product_details/_product_detail.html.erb
<div id="product_list">
<% #products.each do | product | %>
<div class="product_container">
<div class="product_box" >
<div id="future_image_container">
<div class="image_block" >
<%= image_tag(product.image_path, :alt => "product image", :height=>"215px") %>
</div>
<span id="future_price" style="text-decoration: line-through; color: #9e9c9c;">
<span style="color: black;">
<%= "$#{product.price}" %>
</span>
</span>
<div id="circle">
<p>
<% if(product.discount > 0) %>
<% new_price=((2.0*((product.price*product.discount)/100)).round)/2.0 %>
<% else %>
<% new_price=product.price %>
<% end %>
<%= "$#{new_price}"%>
</p>
</div>
</div>
<p class="future_product_name">
<%= product.name %>
</p>
<% #brands=Brand.where("id=?",product.brand_id)
#brands.each do |brand|
#brandname=brand.name
end
%>
<p class="future_product_name">
<%= "Brand : #{#brandname}" %>
</p>
</div>
</div>
<% end %>
</div>
Please help me to solve this problem
I noticed that when i use <%= render #products %> how many items i have taken per page that number of times it repeates. Therefore I solved this by the following code:
In product_details controller
def index
#products=ProductDetail.where("department_id = ? and category_id = ?",1, 1).page(params[:page]).per(15)
end
In product_details/home.html.erb
<div id="product_details">
<%= render 'index' %>
</div>
In product_details/index.js.erb
$('#product_details').html('<%= escape_javascript render ('index') %>');
In product_details/_index.html.erb
<div id="product_list">
<%= paginate #products, :remote=>true %>
<% #products.each do | product | %>
<div class="product_container">
<div class="product_box" >
<div id="future_image_container">
<div class="image_block" >
<%= image_tag(product.image_path, :alt => "product image", :height=>"215px") %>
</div>
<span id="future_price" style="text-decoration: line-through; color: #9e9c9c;">
<span style="color: black;">
<%= "$#{product.price}" %>
</span>
</span>
<div id="circle">
<p>
<% if(product.discount > 0) %>
<% new_price=((2.0*((product.price*product.discount)/100)).round)/2.0 %>
<% else %>
<% new_price=product.price %>
<% end %>
<%= "$#{new_price}"%>
</p>
</div>
</div>
<p class="future_product_name">
<%= product.name %>
</p>
<% #brands=Brand.where("id=?",product.brand_id)
#brands.each do |brand|
#brandname=brand.name
end
%>
<p class="future_product_name">
<%= "Brand : #{#brandname}" %>
</p>
</div>
</div>
<% end %>
</div>
Now no product repeates and ajax pagination is also working fine

Resources