Ruby China
  • Topics
  • 招聘
  • Wiki
  • 酷站
  • Gems
  • Sign Up
  • Sign In
klc
@nowherekai
VIP
NO. 3962 / 2012-10-08

[email protected]
上海
9 Topics / 165 Replies
6 Followers
69 Following
179 Favorites
GitHub Public Repos
  • Gemini-Search 0

    Perplexity style AI Search engine clone built with Gemini 2.0 Flash and Grounding

  • big-AGI 0

    Generative AI suite powered by state-of-the-art models and providing advanced AI/AGI functions. I...

  • ore-cli 0

  • ord 0

    👁‍🗨 Rare and exotic sats

  • fully-local-pdf-chatbot 0

  • opengpts 0

  • RSSAggregatorforAI 0

  • mealmetrics-copilot 0

  • msigner 0

    msigner is an open source Bitcoin Ordinals Partially Signed Bitcoin Transactions (PSBT) signer li...

  • klc-vim 0

    my ~/.vim directory

More on GitHub
  • Overview
  • Topics
  • Replies
  • Favorites
  • Following
  • Followers
  • 修改用户信息提示错误:param is missing or the value is empty: user at January 07, 2016

    我又仔细看了一下你的 settings 方法,你写的有点问题,不能

    if @user.update_attributes(basic_params)
        ...
     elsif @user.update_attributes(accounts_params)
        ...
    

    这样写的。先不管你的 accounts,loved 那几个的更新,咱们先这看 basic_params 这一个。 你想做的是点击连接,显示更改设置的表单,然后提交表单后,进行更改操作。和 rails 常用的 edit 和 update 一样,你需要两个 action。 config/route.rb

    resources :users do
      member do
          get :settings 
         post :update_settings
      end
    end
    

    user_controller.rb

    def settings
      @user = User.find params[:id]
    end
    def update_settings
      @user = User.find_by_id(params[:id])
    
        if @user.update_attributes(basic_params)
           redirect_to ...
        else
           render :settings
       end
    end
    

    form_for 中的 url 也需做相应修改。

  • 修改用户信息提示错误:param is missing or the value is empty: user at January 07, 2016

    路由写错了,把你 config/route.rb 代码贴出来。 你的 users_controller 的 settings 方法即处理 get 请求,又处理 post 请求,自然会报错了。 点击 <li><%= link_to "信息修改", settings_user_path(current_user) %></li> 链接,经过路由后,到达 settings 这个 action,这时候又不是提交的表单,basic_params 函数里面的 params.require(:user) 没有 :user 参数,报错。

  • 修改用户信息提示错误:param is missing or the value is empty: user at January 07, 2016

    你的路由代码怎么得出这个的?路由代码全贴出来

    settings_user GET    /users/:id/settings(.:format)           users#settings
                             POST   /users/:id/settings(.:format)           users#settings
    

    出错的日志不全,全贴出来

  • Rails association 中的 foreign keys at January 05, 2016

    #3 楼 @hanluner MySQL 不建议使用外键,没听说过啊,为什么?

  • 物理隔离的环境如何部署 ROR 项目? at January 05, 2016

    gemstash?

  • Rails 简单搜索求教 at January 05, 2016

    search action 中 @cma 在哪赋的值?controller 的代码全贴出来

  • 送几本《AngularJS 学习手册》 at January 04, 2016

    下面的 +1 就 9 个了

  • 能否举出各种例子,关于 Ruby 可以做一件事用很多方法? at December 31, 2015
    l = -> (x) {  puts x }
    l.call(1)
    l.(2)
    l[3]
    
  • Rails 创建自定义主键执行迁移后数据库中未被设置为主键 at December 31, 2015

    去掉 id: false 和 t.string dept_id, null: false

    create_table :depts,primary_key: :dept_id do
    
  • 关键词 while 有没有返回值? at December 30, 2015

    看文档要仔细, gets:

    Returns (and assigns to $_) the next line from the list of files in ARGV (or $*)...

    print:

    If no arguments are given, prints $_.

  • 2.3.0 悄无声息的发布了? at December 25, 2015

    对 mazt 关于 2.3 的一个采访 https://blog.heroku.com/archives/2015/12/25/ruby-2-3-0-on-heroku-with-matz

  • Rails 映射已有数据库后建立模型关系 at December 24, 2015
    belongs_to :A, foreign_key: "XXX", primary_key: "XXX"
    

    看文档 Options 那一节的说明

  • Rails SQL 查询语句不会立即执行? at December 09, 2015

    没有“似乎是因为 ruby 变量只有在第一次使用的时候才会确定它的值?依稀有这个概念,但是不太确定。”这回事。 videos = Video.where(:task_id => correct_ids) 返回一个 ActiveRecord_Relation 对象,它是 lzay 的,在使用的时候才执行查询数据库的动作。

  • Swift 开源了 at December 04, 2015

    10000+ star 了!

  • JS 里面使用 return false 无效 at November 04, 2015

    onclick: "return validate();" 注意后面的分号

  • 论坛打赌,请众位大神来评判 at October 31, 2015

    #8 楼 @xiaoronglv key 存在 b1 和 b2 的同一个 RClass 中。object 的 c 代码如下:

    struct RObject {
        struct RBasic basic;
        union {
        struct {
            long numiv; #实例变量数量
            VALUE *ivptr; #存放实例变量的数组
                struct st_table *iv_index_tbl; #指向类的iv_index_tbl,是一个hash,key/value分别为变量名/变量位于变量数组的index
        } heap;
        } as;
    };
    

    object 每次新增变量的时候,都会在 iv_index_tbl 这个 hash 中添加一个 key/value,对应变量名/index,然后 ivptr[index] 设为变量值。查找变量的时候是根据变量名找到对应的 index,从 ivptr 中取出。 代码在 variable.c 中。

  • 论坛打赌,请众位大神来评判 at October 31, 2015
    struct RClass {
        struct RBasic basic;
        struct st_table *iv_index_tbl;
    };
    

    实例变量的名字在类里面,st_table 是个 hash。 在我看来,没有本质这种说法,只是实现的细节不同,可以用数组实现,也可以用 hash 实现。

  • 安利一下 rubytogether.org at October 12, 2015

    补个创始人自己的介绍页面 http://arko.net/ 还有一期 podcast https://devchat.tv/ruby-rogues/224-rr-ruby-together-with-andr-arko

  • 评论 Why I wouldn’ t use rails for a new company at September 28, 2015

    “New Company“不应该纠结语言/框架,用熟悉的那个就行,过多的考虑并发/性能问题是过早优化。

  • [上海][2015年9月8日] Ruby 聚会召集 at September 08, 2015

    我也去

  • GitHub: Scaling on Ruby, with a nomadic tech team at August 28, 2015

    github 有一千万的用户,github.com 用的是 Rails 和 MySQL,有用 redis,关键是非常快。 技术上比较保守,没用什么高大上的技术。

  • Rails 中如何实现登录次数尝试过多锁定十分钟 at August 24, 2015

    #6 楼 @rei 这样写有点问题,默认的FileStore 的increment在 key 不存在的情况下是不会加 1 的。 文档:Increments an already existing integer value that is stored in the cache. If the key is not found nothing is done.

  • 使用 Redis 处理 Rails Model 缓存 at July 31, 2015

    为啥不用 Rails.cache.fetch?

  • Rails cache store 的一个疑问:memcached (或 redis) 比 FileStore 有什么好处? at July 21, 2015

    那篇文章作者对 fetch 的benchmark 代码在这里,我摘一部分在下面,结果 5 楼贴了。我自己也跑了一下他的代码,结果类似。对 memcached 和 redis 不是太熟,所以不知道为什么会比 FileStore 慢。

    Benchmark.ips do |x|
      file_store = ActiveSupport::Cache::FileStore.new("tmp/cache")
      x.report(file_store.class) { file_store.fetch(rand(KEY_SIZE)) { :value } }
    
      memory_store = ActiveSupport::Cache::MemoryStore.new
      x.report(memory_store.class) { memory_store.fetch(rand(KEY_SIZE)) { :value } }
    
      lru_redux = LruRedux::ThreadSafeCache.new(1_000)
      x.report(lru_redux.class) { lru_redux.getset(rand(KEY_SIZE)) { :value } }
    
      dc = ActiveSupport::Cache::DalliStore.new('localhost:11211')
      dc.clear
      begin
        dc.dalli.alive!
        x.report(dc.class) { dc.fetch(rand(KEY_SIZE)) { :value } }
      rescue Dalli::RingError
        puts "Not running Memcache bench - you must have a Memcache server available"
      end
       ...
    
  • 写一个 rake 任务将 yml 文件写入数据库当中 at July 02, 2015

    #2 楼 @rei 请教,不用 rake 的话还可以用什么?因为 rake 可以方便调用 ActiveRecord

  • 【已解决】付宝移动支付异步 POST 请求处理问题 at July 01, 2015

    这个问题其实是因为你不会debug 比如用楼上的方法

    def create
      b = Bill.create bill_params
      Rails.loger.debug "debug0: #{b.error.full_messages}"
    end
    
  • 【已解决】付宝移动支付异步 POST 请求处理问题 at June 30, 2015

    controller 代码贴出来

  • 在 Ruby on Rails 中,我怎么能在 controller 中打印从数据库中取出的数据呢? at June 29, 2015

    你想显示在页面上吧?在 view(.erb) 里面,这样 <%= debug params %>

  • Rails Server 与 Apache 的比较 at June 23, 2015

    可以看看这篇。刚学的话这些不懂也没关系,用多了就懂了。

  • 有离线听 5by5 的安卓软件么? at June 06, 2015

    Pocket Casts,Google Play 有付费正版。AntennaPod 免费的。

  • Prev
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • Next
关于 / RubyConf / Ruby 镜像 / RubyGems 镜像 / 活跃会员 / 组织 / API / 贡献者
由众多爱好者共同维护的 Ruby 中文社区,本站使用 Homeland 构建,并采用 Docker 部署。
服务器由 赞助 CDN 由 赞助
iOS 客户端 / Android 客户端 简体中文 / English