sudo /usr/local/mysql/support-files/mysql.server start
sudo /usr/local/mysql/support-files/mysql.server stop
What is a proposition?
vor 15 Jahren
This is absolutely a private note pad for my use only - it is just a list of things that I took ages to find out OR don't want to forget all in one place for me to refer to later. Anyone who finds it can read it - and thats all. Don't come crying to me about anything in it. I did not write for you or the world.
>sudo gem install ZenTest
>sudo gem install rspec-rails
in application root:
>ruby script/generate rspec
autotest (if it hangs use >RSPEC=true autotest)
rake spec
rake spec:app
rake spec:models
rake spec:controllers
rake spec:views
rake spec:helpers
rake spec:plugins
rake --tasks:plugins
Add the following to application.rb
<% link_to("award", certificate_path(1)%>
map.resources :certificates
map.the_certificate 'award', :controller => certificates, :action => 'show', id => 1
map.resources :certificates
<% link_to("award", certificate_path(1)%> to <% link_to("award", the_certificate_path %>
map.certificate 'award', :controller => certificates, :action => 'show', id => 1
map.resources :certificates
certificate:
..id: 1
..title: "All About This Certificate"
..description: "Blah Blah."
..id: 2
..title: "All About This Certificate"
..description: "More Blah Blah."
==== Create Load Migration example
class LoadCertificatesData <>
..def self.up
....down
....directory=File.join(File.dirname(__FILE__),"development_data")
....Fixtures.create_fixtures(directory,"certificates")
..end
..def self.down
....Certificate.delete(:all)helper_method :cookies_on?
protected
def cookies_on?
..request.cookies["_appname_session"].to_s.include?('_appname_session')
end
config.action_controller.session = {
:session_key => '_appname_session',
:secret => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
}
<% if cookies_on? %>
# show the form with the submit button
<% else %>
# show the form without the submit button and display a message telling the user that this site protects the identiy of users with coded cookies and they cannot sumbit the form without cookies enabled in the browser.
<% end %>
class AddPrice
...def self.up
.....add_column :products, :price, decimal, :precision => 8, :scale => 2, :default => 0
...end
...def self.down
......remove_column :products, :price
...end
end
def Order < ActiveRecord::Base
has_many :line_items
belongs_to :customer # there's a column "customer_id" in the db table
end
def LineItem < ActiveRecord::Base
belongs_to :order # there's a column "order_id" in the db table
end
def Customer < ActiveRecord::Base
has_many :orders
has_one :address
end
def Address < ActiveRecord::Base
belongs_to :customer
end
belongs_to :some_model,
:class_name => 'MyClass', # specifies other class name
:foreign_key => 'my_real_id', # and primary key
:conditions => 'column = 0' # only finds when this condition met
has_one :some_model,
# as belongs_to and additionally:
:dependent => :destroy # deletes associated object
:order => 'name ASC' # SQL fragment for sorting
has_many :some_model
# as has_one and additionally:
:dependent => :destroy # deletes all dependent data
# calling each objects destroy
:dependent => :delete_all # deletes all dependent data
# without calling the destroy methods
:dependent => :nullify # set association to null, not
# destroying objects
:group => 'name' # adds GROUP BY fragment
:finder_sql => 'select ....' # instead of the Rails finders
:counter_sql => 'select ...' # instead of the Rails counters
validates_presence_of :firstname, :lastname # must be filled out
validates_length_of :password,
:minimum => 8 # more than 8 characters
:maximum => 16 # shorter than 16 characters
:in => 8..16 # between 8 and 16 characters
:too_short => 'way too short'
:too_long => 'way to long'
validates_acceptance_of :eula # Must accept a condition
:accept => 'Y' # default: 1 (ideal for a checkbox)
validates_confirmation_of :password
# the fields password and password_confirmation must match
validates_uniqueness_of :user_name # user_name has to be unique
:scope => 'account_id' # Condition:
# account_id = user.account_id
validates_format_of :email # field must match a regular expression
:with => /^(+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i
validates_numericality_of :value # value is numeric
:only_integer => true
:allow_nil => true
validates_inclusion_of :gender, # value is in enumeration
:in => %w( m, f )
validates_exclusion_of :age # value is not in Enumeration
:in => 13..19 # don't want any teenagers
validates_associated :relation
# validates that the associated object is valid
Options for all validations above:
:message => 'my own errormessage' # eigene Fehlermeldung
:on => :create # or :update (validates only then)
:if => ... # call method oder Proc
<%= file_field_tag :dvd_data %>
<%= submit_tag 'Create' %>