Ruby China
  • 社区
  • 招聘
  • Wiki
  • 酷站
  • Gems
  • 注册
  • 登录
蒋文辉
@Allen_hui
会员
第 36983 位会员 / 2019-02-15

6 篇帖子 / 9 条回帖
0 关注者
0 正在关注
2 收藏
未设置 GitHub 信息。
  • 概况
  • 话题
  • 回帖
  • 收藏
  • 正在关注
  • 关注者
  • 新手关于 ruby 符号 &. 的问题,不明白是什么意思?如何定义做到可以这样使用的? at 2019年09月03日

    好的,感谢

  • Rails 中如何实现自定义下拉框中的显示内容 at 2019年03月15日

    是的,只写一个当前值是因为我只需要写入当前选中的 user_id 即可,而我又想区分重名的人,方便来进行精确的选择。。

    好的,我研究一下,感谢!

  • Rails 中如何实现自定义下拉框中的显示内容 at 2019年03月15日

    为空,报错。。。我明白了,我应该是拿错 model 对象了,,在未提交前新建的@recording的对象属性还是空的,我应该去拿拥有这些属性的 model,对吗?

  • Rails 中如何实现自定义下拉框中的显示内容 at 2019年03月15日

    不是空的,在选择前用户的相关信息就都是齐全的了

  • Rails 中如何实现自定义下拉框中的显示内容 at 2019年03月15日
    <div class="form-group row <%= f.object.errors.include?(:user_id) ? 'has-danger' : '' %>">
      <label class="col-md-2 form-control-label" for="select">
        用户
        <font color="red">
          <i class='fa fa-star fa-sm mt-1'></i>
        </font>
      </label>
      <div class="col-md-4 has-danger">
        <%= f.select :user_id, [], {include_blank: '请输入用户姓名'}, class: 'select2 form-control user_id_ajax' do %>
          <% if @recording.user %>
            <option value="<%= @recording.user_id %>" selected="selected"><%= "#{@recording.user.name}/#{@recording.user.department.name}" %></option>
          <% end %>
        <% end %>
      </div>
    </div>
    

    我是这么做的,但是在下拉框的中,并没有生效,只有在表单提交了之后,再去看显示结果才显示出来,在选择的时候只有名字字段显示

  • 添加字段后,启动,本地跑起来一点问题都没有,,放到线上发布后就报错 at 2019年03月06日

    嗯嗯,感谢提醒

  • 添加字段后,启动,本地跑起来一点问题都没有,,放到线上发布后就报错 at 2019年03月06日

    对的,就是 Course.column_type 这个地方出的问题,终于顺着这个地方去排查,找到原因了,感谢!!

  • 添加字段后,启动,本地跑起来一点问题都没有,,放到线上发布后就报错 at 2019年03月06日

    部署线上是用 cap 一键部署的,去线上的数据库里面查看了,但这个字段已经有了,还是报错。。这就是这个问题的奇怪之处,弄了好久都没弄明白咋回事

  • 添加字段后,启动,本地跑起来一点问题都没有,,放到线上发布后就报错 at 2019年03月06日

    controller.rb

    def new
        @course = Course.new
      end
      private
    
      def course_params
        params[:course][:price] = 0 if params[:course][:price].blank?
        params.require(:course).permit(:topic, :cover, :introduction, :column_type)
      end
    
    

    _form.html.erb

    <div class="form-group row <%= f.object.errors.include?(:column_type) ? 'has-danger' : '' %>">
                <label class="col-md-2 form-control-label" for="select">
                  所属栏目
                </label>
                <div class="col-md-10 has-danger">
                  <%= f.select :column_type, options_for_select(Course.column_type.options, @course.column_type), {include_blank: '请选择'}, class: 'select2 form-control' %>
                </div>
              </div>
    

    model.rb

    class Course < ApplicationRecord
      acts_as_paranoid
      extend Enumerize
      enumerize :column_type, in: { hot_spot: 1, life: 2}
    
关于 / RubyConf / Ruby 镜像 / RubyGems 镜像 / 活跃会员 / 组织 / API / 贡献者
由众多爱好者共同维护的 Ruby 中文社区,本站使用 Homeland 构建,并采用 Docker 部署。
服务器由 赞助 CDN 由 赞助
iOS 客户端 / Android 客户端 简体中文 / English