scaffoldなんか使わない

iftbテーブルがある。手動でイロイロ作る。

ファイル作成

コントローラー

/app/controllers/iftbs_controller.rb

#encoding: utf-8
class IftbsController < ApplicationController
  def top
  end
end

とりあえすtopだけ作る

ヘルパー

今は不要なので作らない

モデル

/app/models/iftb.rb

#encoding: utf-8
class Iftb < ActiveRecord::Base
end

中身は特に無し

ビュー

/app/viwes/iftb/top.html.erb
中身はスッカラカン

確認

rails s」でhttp://localhost:3000/iftbs/topが表示された

 

新規登録画面作成

コントローラー

/app/controllers/iftbs_controller.rb

  # 新規登録画面を表示する
  def new
    @iftb = Iftb.new
    @iftb.staff_id = @current_user.member_id unless @current_user.nil?
  end

追加する。

ビュー1

/app/viwes/iftb/new.html.erb

<h2>新規作成</h2>
<%= error_messages_for(:iftb) -%>
<%= form_for :iftb, :url=>{:action=>:create, :id=>@iftb}, :html=>{:name=>"frm"} do |f| -%>
	<%= render :partial=>'form', :locals=>{:context=>'new', :f=>f} %><br/>
	<%= submit_tag '登録する', :disable_with=>'登録中・・・' , :class=>'submit_button' %>
	<%== link_back %>
<%- end -%>

フォームのところはedit.html.erbと共用したいので別ファイルにする。

ビュー2

/app/viwes/iftb/_form.html.erb

<table>
<%- attr = 'activerecord.attributes.iftb.' -%>
<%- if context != 'new' -%>
<tr>
	<th><%= t(attr+'id') -%></th>
	<td colspan=3><%= @iftb.id %></td>
</tr>
<%- end -%>
<tr>
    <th><%= required -%><%= t(attr+'dtstart') -%></th>
    <td colspan=3><%= f.datetime_select(:dtstart, :use_month_numbers=>true) %></td>
</tr>
</table>

こんな感じ