Skip to content

Instantly share code, notes, and snippets.

View ojiry's full-sized avatar
💪

Ryoji Yoshioka ojiry

💪
View GitHub Profile
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
<%= form_for(@user) do |f| %>
<%= f.hidden_field :name %>
<%= f.hidden_field :age %>
<p>
<b>Name:</b>
<%= @user.name %>
</p>
<p>
<b>Age:</b>
<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>
helloWorld = () -> alert "Hello World!"
# <%= link_to_function 'greeting', "helloWorld();" %>
@helloWorld = () -> alert "Hello World!"
(function() {
var helloWorld2;
// @helloWorld
this.helloWorld = function() {
return alert("Hello World!");
};
// helloWorld2
helloWorld2 = function() {
return alert("Hello World!");
};
a = [1, 2, 3, 4, 5, 6, 5, 4]
a.uniq.select{|i| a.index(i) != a.rindex(i)} #=> [4, 5]
<!-- 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" } %>
# 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
$ heroku pg:reset --db SHARED_DATABASE_URL
! The --db option has been deprecated
! Usage: heroku pg:reset [DATABASE]
# 怒られたので
$ heroku pg:reset SHARED_DATABASE_URL
SHARED_DATABASE_URL is deprecated, please use SHARED_DATABASE
----> Resetting SHARED_DATABASE (DATABASE_URL)
! WARNING: Potentially Destructive Action
! This command will affect the app: [アプリ名]