Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pair seito sueyoshi #5

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ source 'https://rubygems.org'
#ruby-gemset=yochigaya

gem 'rails', '~> 4.0.0'
gem 'ruby_cowsay'

group :development, :test do
gem 'sqlite3'
Expand Down
6 changes: 6 additions & 0 deletions app/controllers/static_pages_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
class StaticPagesController < ApplicationController
def home
@cowsay = Cowsay.new
end

def help
end

def cowsay
words = %w(seito sueyoshi)
@cowsay = Cowsay.new(word: words.sample)
end
end
11 changes: 11 additions & 0 deletions app/models/cowsay.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
require 'ruby_cowsay'

class Cowsay
include ActiveModel::Model

attr_accessor :word

def exec
Cow.new.say(word)
end
end
7 changes: 7 additions & 0 deletions app/views/static_pages/cowsay.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<%= form_for @cowsay, url:"/static_pages/cowsay" do |f| %>
<%= f.submit value="ボタン" %>
<% end %>

<pre>
<%= @cowsay.exec %>
</pre>
6 changes: 3 additions & 3 deletions app/views/static_pages/home.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<form>
<button>ボタン</button>
</form>
<%= form_for @cowsay, url:"static_pages/cowsay" do |f| %>
<%= f.submit 'ボタン' %>
<% end -%>
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Yochigaya::Application.routes.draw do
root 'static_pages#home'
get 'static_pages/help'
post 'static_pages/cowsay'
# The priority is based upon order of creation: first created -> highest priority.
# See how all your routes lay out with "rake routes".

Expand Down