helper默認是只在view中可用的,如果在controller中也要使用,要在ApplicationController中 include
如果model中如果有叫做type的列的話,會觸發rails的Single Table Inheritance ,放棄它吧,不好用,還是安心使用外鍵約束吧。給model加上self.inheritance_column = nil disable它
controller中的參數變量會傳到對應的view中比如:
def new@user = User.new end---------------------------------new.html.erb---------------------- <%= form_for(@user) do |f| %><%=f.label :name %><%=f.text_field :name %><%=f.label :email %><%=f.text_field :email %><%=f.label :type %><%= f.select(:type, options_for_select([['admin', 'admin'], ['teacher', 'teacher'], ['student', 'student']])) %><%=f.label :password %><%=f.password_field :password %><%=f.label :password_confirmation %><%=f.password_field :password_confirmation %><%= f.submit "Create my account"%> <% end %>
?