I saw a feature in Ext JS document - http://dev.sencha.com/deploy/ext-4.0.1/examples/grid/locking-grid.html. We can lock a column by set the option "locked" according the document, but when I did this in Netzke Grid, the grid disappears. Is there any specific method to achieve this. Below the sample code is given,
def configure(c)
super
c.model = "Product"
c.title = "Product List"
c.columns = [
{
:name => :name,
:text => "Name",
:read_only => true,
:locked => true
},
{
:name => :price,
:text => "Price"
},
{
:name => :date,
:text => "Date"
}
]
end
Related
My sign up page has login. email, password, password_confirm and company fields . All of them are supposed to be mandatory but when i click on sign up it is not checking if any fields except password and password_confirm are blank!! I dont understand what is the difference as in my app/models/user.rb file i have validates presence for all fields. Please help me
Here's code(required lines)
user.rb
class User < ActiveRecord::Base
has_many :excel_files # One user may have many excel files
has_one :user_access_validity# One user may have one license period
# Virtual attribute for the unencrypted password
attr_accessor :password
attr_accessible :login
attr_accessible :email
attr_accessible :password
attr_accessible :password_confirmation
attr_accessible :company
#changes of 'validates' in accordance with rails 3:
validates :login, :presence => true,
:length => { :within => 3..40},
:uniqueness => { :case_sensitive => false },
:format => { :with => /^([a-z_0-9\.]+)$/i },
:on => :create,
:if => :is_login_entered?
validates :email, :presence => true,
:length => { :within => 7..100},
:uniqueness => { :case_sensitive => false },
:format => {:with => /^([a-z]+((\.?)|(_?))[a-z0-9]+#(mindtree.com|rvce.edu.in))$/i},
:on => :create,
:if => :is_email_entered?
validates :company, :presence => true,
:format => { :with =>/(mindtree|RVCE)/i},
:format => { :with => /^([a-z]+)$/i },
:on => :create,
:if => :is_company_entered?
validates :password, :presence => true,
:length => { :within => 4..40 },
:confirmation => true,
:format => { :with => /^([a-z0-9#!#\$]+)$/i },
:on => :create,
:if => :password_required?
validates :password_confirmation, :presence => { :if => :password_required? }
before_save :encrypt_password
#
# is_email_entered? : checks whether the email field is entered or not
# #params : none
# #return : true - if the email is entered
# false - if the email is not entered
#
def is_email_entered?
!self.email.blank?
end
#
# is_company_entered? : checks whether the company field is entered or not
# #params : none
# #return : true - if the company is entered
# false - if the company is not entered
#
def is_company_entered?
!self.company.blank?
end
#
# is_login_entered? : checks whether the login field is entered or not
# #params : none
# #return : true - if the login is entered
# false - if the login is not entered
#
def is_login_entered?
!self.login.blank?
puts "login"
end
protected
#
# password_required? : Checks whether either of the crypted_password and password field is blank
# #params : none
# #return : true - if either of the crypted_password and password field is blank
# false - if either of the crypted_password and password field is not blank
#
def password_required?
crypted_password.blank? || !password.blank?
puts "in pr?"
end
end
controller.rb
def signup
if logged_in?
flash[:notice] = "<span class='error'>You have already registered with us!</span>".html_safe
redirect_to :action => 'upload_file'
else
#user = User.new(params[:user])
return unless request.post?
#user.save!
self.current_user = #user
random_number = #user.generate_random_number
puts random_number
new_random_number = "c" + #user.id.to_s + random_number
#user.customerid = new_random_number
#user.created_at = get_current_datetime
# #user.updated_time = ''
#user.save
# save user's maximum access days
user_validity = UserAccessValidity.new
user_validity.user_id = self.current_user.id
user_validity.maximum_access_in_days = 90
user_validity.save
# redirect_back_or_default(:controller => '/account', :action => 'welcome')
redirect_to :controller => '/account', :action => 'welcome'
flash[:notice] = "<span class='success'>Thanks for registering!</span>".html_safe
end
end
signup.html.erb
<font color=red>(Fields marked * are mandatory)</font><h3>Sign me up!</h3>
<br>
<span class='error'><%= error_messages_for (#user) %></span>
<%= form_for :user do |f| -%>
<span class='error'><%= flash[:msg] %></span>
<p><label for="login"><span class='redcolor'>*</span>Login</label><br/>
<%= f.text_field :login %></p>
<p><label for="email"><span class='redcolor'>*</span>Email</label><br/>
<%= f.text_field :email %></p>
<p><label for="password"><span class='redcolor'>*</span>Password</label><br/>
<%= f.password_field :password %></p>
<p><label for="password_confirmation"><span class='redcolor'>*</span>Confirm Password</label><br/>
<%= f.password_field :password_confirmation %></p>
<p><label for="company"><span class='redcolor'>*</span>Company</label><br/>
<%= f.text_field :company %></p>
<p><%= f.submit 'Sign up', :name=> 'sign_up' %></p>
<% end -%>
The problem is that you pass an if option to your validation which also applies to the presence validation. Take for example the following
validates :login,
:presence => true,
:length => { :within => 3..40},
:uniqueness => { :case_sensitive => false },
:format => { :with => /^([a-z_0-9\.]+)$/i },
:on => :create,
:if => :is_login_entered?
is_login_entered? is called when validating the presence of login which conflicts with the validation which is why the validation is skipped. Change your validation to
validates :login, :presence => true, :on => :create
validates :login,
:length => { :within => 3..40},
:uniqueness => { :case_sensitive => false },
:format => { :with => /^([a-z_0-9\.]+)$/i },
:on => :create,
:if => :is_login_entered?
This way, the other validations will only run if a login is present.
I have a table, schools with the fields: id, name, address, city, state, zip, latitude and longitude.
I want to search for schools within 12km by giving latitude and longitude; I am using this query but it's not working.
curl -X GET "http://localhost:9200/schools/school/_search?=true" -d '{"filter" : {"geo_distance" : {"distance" :"12km", "location": "40,-70"}}}'
I get the following error:
{
"error":"SearchPhaseExecutionException[
Failed to execute phase [query], total failure;
shardFailures {[_na_][schools][0]: No active shards}{[_na_][schools][1]:
No active shards}{[_na_][schools][2]: No active shards}{[_na_][schools][4]:
No active shards}{[WJV55VsxQU-XW8VPmXImwA][schools][3]:
RemoteTransportException[[Archie Corrigan][inet[/192.168.1.109:9300]][search/phase/query]]; nested:
SearchParseException[[schools][3]: from[-1],size[-1]: Parse Failure [Failed to parse source [
{\"filter\" :
{\"geo_distance\" :
{\"distance\" :\"12km\", \"location\": \"40,-70\"}
}
}]
]
]; nested: QueryParsingException[[schools] failed to find geo_point field [location]];}]",
"status":500
}
model configuration in rails
# ElasticSearch integration
include Tire::Model::Callbacks
include Tire::Model::Search
include Search::ReloadHelper
tire do
settings({
:analysis => {
:filter => Search::Filters.hs_name_filters,
:analyzer => Search::Analyzers.hs_name_analyzers
}
})
mapping do
indexes :id, :type => 'integer', :index => :not_analyzed
indexes :name, :type => 'string', :analyzer => :hs_name_analyzer
indexes :address, :type => 'string', :index => :not_analyzed
indexes :city, :type => 'string', :analyzer => :hs_name_analyzer
indexes :state, :type => 'string', :index => :not_analyzed
indexes :zip, :type => 'integer', :index => :not_analyzed
indexes :location, :type => 'geo_point', :lat_lon => true
end
end
def to_indexed_json
{
:id => id,
:name => name,
:address => address,
:city => city,
:state => state,
:zip => zip,
:location => {
:lat => latitude,
:lon => longitude
}
}.to_json
end
How can I get this to work?
Is there any easy way to include the multiupload feature to NetzkeFormView or GridView(AddInForm)?
My current image uloading field with carrierwave is:
{:name => :image_link, :xtype => :displayfield, :display_only => true, :getter => lambda { |r| %Q(<a href='#{r.image.url}'>Download</a>) if r.image.url }},
{:name => :image, :field_label => "Upload image", :xtype => :fileuploadfield, :getter => lambda { |r| "" }, :display_only => true}
I want to validate the email only if the email has been entered.
I tried the following:
validates :email, :presence => {:message => "Your email is used to save your greeting."},
:email => true,
:if => Proc.new {|c| not c.email.blank?},
:uniqueness => { :case_sensitive => false }
However this does not work as it stops error messages from showing when the email is left blank.
How can I validate the presence of the email when it is missing and ONLY validate the format when it has been entered?
This should do the trick.
validates :email,:presence => {:message => "Your email is used to save your greeting."}, :allow_blank => true,:uniqueness => { :case_sensitive => false }
Use:allow_blank => true or :allow_nil => true, :if => :email?
edit: fix typo.
You can write custom validation function:
class Model < ActiveRecord::Base
validate :check_email
protected
def check_email
if email.blank?
validates :email, :presence => {:message => "Your email is used to save your greeting."}
else
validates :email,
:email => true,
:uniqueness => { :case_sensitive => false }
end
end
end
or divide your validator into 2 separate validators with conditions:
validates :email,
:presence => {:message => "Your email is used to save your greeting."},
:if => Proc.new {|c| c.email.blank?}
validates :email,
:email => true,
:uniqueness => { :case_sensitive => false }
:unless => Proc.new {|c| c.email.blank?}
you can validate format if no precense required
:allow_nil => true
I am using rails 3.1.0.rc3 with formtastic 2.0.0.rc2 and I am getting this error -
undefined method `inputs' for #<ActionView::Helpers::FormBuilder:0x000001059c2fb0>
Here is the block of code
= form_tag '#', :class => 'formtastic' do
= fields_for CustomFields::Field.new, :builder => Formtastic::Helpers::FormHelper.builder do |g|
= g.inputs :name => :attributes do
= g.input :_alias
= g.input :hint
= g.input :text_formatting, :as => 'select', :collection => options_for_text_formatting, :include_blank => false, :wrapper_html => { :style => 'display: none' }
= g.input :target, :as => 'select', :collection => options_for_association_target, :include_blank => false, :wrapper_html => { :style => 'display: none' }
Is this a bug ?
Thanks, Alex
You are trying to use a formtastic method here. When you are actually in a block for Rails's form builder.
You need semantic_form_for and formtastic in your Gemfile to use f.inputs for example..