rails开发随手记-0
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 %>