Ruby China
  • 社区
  • 招聘
  • Wiki
  • 酷站
  • Gems
  • 注册
  • 登录
@messiahxu
高级会员
第 481 位会员 / 2011-12-15

南京
2 篇帖子 / 229 条回帖
1 关注者
0 正在关注
90 收藏
未设置 GitHub 信息。
  • 概况
  • 话题
  • 回帖
  • 收藏
  • 正在关注
  • 关注者
  • Rails 的 layout 会自动引入目录下的 css 以及 js 吗? at 2013年10月27日

    #3 楼 @MIx 默认只会载入和 application.css 一个目录层级的,要载入子目录下的,就必须在默认载入的 stylesheet 里面配置 require_tree .

  • Rails 的 layout 会自动引入目录下的 css 以及 js 吗? at 2013年10月27日

    你该不会是放在 assets/stylesheets/bootstrap/ 下了吧

  • Devise 登录和注册怎么写对应 json 的请求???? at 2013年10月21日

    #2 楼 @ChanceDoor 因为 devise 现在默认不会相应 json,所以必须设置一下。

  • Devise 登录和注册怎么写对应 json 的请求???? at 2013年10月20日

    是不是发现取不到 current_user 啊 config/appliacation.rb

    config.to_prepare do
      DeviseController.respond_to :html,:json
    end
    
  • 高度集中持续写 12 小时代码你有什么感觉? at 2013年10月14日

    不正常,楼主你肯定是怀孕了〜

  • Chrome 如何测试 hover mouse at 2013年09月28日

    #2 楼 @QueXuQ 右边 Styles 那一行 加号 旁边那个,点开勾选 :hover 就行了

  • 每次部署到服务器后数据库和表就没了,gitignore 文件写了 db/*.sqlite3 at 2013年09月19日

    #2 楼 @tyaccp_guojian 那部署之后 rake db:create migrate 了吗……

  • 每次部署到服务器后数据库和表就没了,gitignore 文件写了 db/*.sqlite3 at 2013年09月19日

    数据库想部署到服务器的话,似乎不应该在 .gitignore 里写才对吧

  • No route matches {:action=>"update_type", :controller=>"users"} at 2013年09月18日

    UsersController 里面

    def create
       @user = User.new(user_params)
        if @user.save
        flash[:success] = "Welcome to the Sample App!"
        render 'select_type'
        else
         render 'new'
        end
      end
    

    为什么要 render?render 的话,select_type 和 update_type 都是取不到 params[:id] 的,因为取不到这个值,所以

    <%= form_for( @user,url: {action: "update_type"} , html: {method: "patch"}) do |f| %>
    

    这里的 action: "update_type",就会以为你要的 url 是 /users/update_type,很明显,你的 routes 里面没有符合的,于是就报错说

    No route matches {:action=>"update_type", :controller=>"users"}
    

    这时候,只需要把 render 'select_type' 改成

    redirect_to select_type_user_path(@user)
    

    就好了。 至于你问的下面

    <%= form_for( @user,url: update_type_user_path(@user) , html: {method: "patch"}) do |f| %>
    <%= form_for( @user,url: {action: "update_type"} , html: {method: "patch"}) do |f| %>
    

    这俩的区别,相信看了我上面说的那么多,你应该已经知道了。

  • 关于使用 form_tag 提交表单 at 2013年09月13日

    什么叫做动态的文本框……

  • Rails 中如何设置自连接类型 at 2013年09月12日

    #3 楼 @ytwman 原生支持的干嘛要用插件……

  • couldn't find file 'jquery-ui at 2013年09月09日

    #2 楼 @jiwoorico As of v3.0, jquery-rails no longer includes jQuery UI. Use the jquery-ui-rails gem

  • ubuntu 里面是否有合适的查看 sqlite3 文件的软件 at 2013年09月09日

    sqlitebrowser

  • couldn't find file 'jquery-ui at 2013年09月09日

    是不是用了 jquery-ui-rails ?

  • 女人更看重什么 at 2013年09月07日

    有针对性的找对象本身就是一种耍流氓的行为

  • 评论删除的问题 at 2013年09月02日

    git clone 了一下居然花了我一分多钟,对你在 代码里面加视频的做法表示无法理解……

    def destroy
      @nutrition = Nutrition.find(:id) # params[:id]
      @nutrition.destroy
      ...
    end 
    
  • Rails 中如何设置自连接类型 at 2013年09月01日
    rails g model Employee name:string manager_id:integer
    rake db:migrate
    
    class Employee < ActiveRecord::Base
        has_many :subordinates, class_name: "Employee", foreign_key: "manager_id"
        belongs_to :manager, class_name: "Employee"
    end
    
    manager = Employee.create(name: "test_of_manager")
    s = manager.subordinates.create(name: "test_of_subordinate")
    manager.subordinates
    s.manager
    
  • ActiveRecord 虚拟属性 (Virtual Attribute) 的问题 at 2013年08月31日

    #2 楼 @ljdam 看这里 http://api.rubyonrails.org/classes/ActiveRecord/Serialization.html#method-i-to_xml

  • 访问别人的文章出错的问题 (ruby on rails tutorial) at 2013年08月31日

    #26 楼 @runup 你可以

    rake routes
    

    一下,然后在结合着 http://guides.rubyonrails.org/routing.html 看。

  • 看了大半天 Mongoid 网上的教程,还是不知道怎么用 at 2013年08月30日

    #3 楼 @leeboqiang

    rails g mongoid:config
    

    了吗?

  • 程序员不易找对象的原因 at 2013年08月27日

    长相问题不要怪职业

  • ActiveRecord 虚拟属性 (Virtual Attribute) 的问题 at 2013年08月26日
    @custom.to_xml methods: [:distince]
    
  • 文章评论添加的问题 at 2013年08月26日

    #26 楼 @runup

    @comment = @two.comments.new(...)
    

    这里面新建的 @comment 会自动加入 two_id 的属性,所以你只需要手动指定 user_id 就可以了。 或者你这么看

    @two = Two.find(params[:id])
    @user = current_user
    @comment = Comment.new(two_id: @two.id, user_id: @user.id, ...)
    @comment = @two.comments.new(user_id: @user.id, ...)
    

    上面这两个 @comment 是一样的,这样你就明白了吧。

  • 推荐一本对你影响最大的书 at 2013年08月25日

    传习录

  • 文章评论添加的问题 at 2013年08月24日

    #23 楼 @runup 因为没有 save 呀……

  • 文章评论添加的问题 at 2013年08月24日

    跟你之前那个帖是同样地问题啊。 首先你这里的

    @user = User.find(current_user)
    

    取到的是当前用户,但是你之后的

    @two = @user.twos.find(params[:id])
    

    这行里,params[:id] 取到的 id 是当前页面的 two 的 id。问题在于,你取到的当前用户是要添加 comment 的用户,而不一定是拥有这个 two 的用户,所以出现 Couldn't find Two without an ID。 而要取得当前页面的 two,可以直接

    @two = Two.find(params[:id])
    

    然后

    @comment = @two.comments.new(user_id: current_user, ...)
    

    你非要反过来的话就得这样

    @user = User.find(current_user)
    @two = Two.find(params[:id])
    @comment = @user.new(two_id: @two.id, ...)
    

    不过要记得,必须要手动指定 user_id,或者 two_id,因为这两个属性不会存在 params[:comment] 里面,另外,Rails 3.2.8 之后 4.0.0 之前,要用 params[:comment] 要记得加上

    attr_accessible: :aaa, :bbb, :ccc
    

    差不多就这样,这些都很基础的,LZ 你先把官方的 Guides 过一遍,基本就懂了。

  • 三个对象互相关联的问题 at 2013年08月24日

    #7 楼 @runup 大概是从 3.2 开始一样的。

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