This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# generate model | |
$ rails g model team name | |
$ rails g model user name age:integer team:references | |
$ rake db:migrate | |
$ sed -n '14,32p' db/schema.rb | |
ActiveRecord::Schema.define(:version => 20120327062610) do | |
create_table "teams", :force => true do |t| | |
t.string "name" | |
t.datetime "created_at", :null => false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Book(id: integer, title: string, created_at: datetime, updated_at: datetime) --> | |
<!-- not multiple --> | |
<%= collection_select 'book', 'id', Book.all, 'id', 'title', { selected: "1" } %> | |
<!-- multiple --> | |
<%= collection_select 'book', 'id', Book.all, 'id', 'title', { selected: ["1", "2", "3"] }, { multiple: "multiple" } %> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a = [1, 2, 3, 4, 5, 6, 5, 4] | |
a.uniq.select{|i| a.index(i) != a.rindex(i)} #=> [4, 5] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
var helloWorld2; | |
// @helloWorld | |
this.helloWorld = function() { | |
return alert("Hello World!"); | |
}; | |
// helloWorld2 | |
helloWorld2 = function() { | |
return alert("Hello World!"); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@helloWorld = () -> alert "Hello World!" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
helloWorld = () -> alert "Hello World!" | |
# <%= link_to_function 'greeting', "helloWorld();" %> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h1>New user</h1> | |
<%= form_for @user, url: new_user_path(user: @user), method: :get do |f| %> | |
<% if @user.errors.any? %> | |
<div id="error_explanation"> | |
<h2><%= pluralize(@user.errors.count, "error") %> prohibited this user from being saved:</h2> | |
<ul> | |
<% @user.errors.full_messages.each do |msg| %> | |
<li><%= msg %></li> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%= form_for(@user) do |f| %> | |
<%= f.hidden_field :name %> | |
<%= f.hidden_field :age %> | |
<p> | |
<b>Name:</b> | |
<%= @user.name %> | |
</p> | |
<p> | |
<b>Age:</b> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def new | |
if params[:user] | |
@user = User.new(params[:user]) | |
render @user.valid? ? :confirm : :new | |
else | |
@user = User.new | |
respond_to do |format| | |
format.html # new.html.erb | |
format.json { render json: @user } | |
end |
NewerOlder