草庐IT

user_users

全部标签

ruby-on-rails - 没有路由匹配 { :action= >"show", :controller= >"users"} 错误

我正在进行以下操作:users_controller_spec中的rspec测试:it"shouldredirecttotheusershowpage"dopost:create,:user=>@attrresponse.shouldredirect_to(user_path(assigns(:user)))end在我的users_controller中,我有以下内容:defshow@user=User.find(params[:id])@title=@user.nameenddefcreate@title="Signup"@user=User.new(params[:user])if

ruby-on-rails - rails : How can I let my users choose a design?

我正在使用Rails并尝试在我的博客应用程序中实现一个功能。我想要为我的博客选择设计的选项。我当然会进行设计并对其进行编码,但在对它们进行编码后,我希望可以选择使用我的设计之一。我会/应该如何处理这个问题? 最佳答案 制作用于选择设计表单列表的Controller(当然要检查选择的有效性)。在session中保存选择并试试这个:在布局中:=stylesheet_link_tag@custom_css在application.rb中classApplicationController我认为这应该可行。另一个想法是改变不同的布局。cla

ruby-on-rails - spree 1.3 : How to only show users products available in their size

关闭。这个问题不符合StackOverflowguidelines.它目前不接受答案。要求提供代码的问题必须表现出对所解决问题的最低限度理解。包括尝试过的解决方案、为什么它们不起作用,以及预期结果。另请参阅:StackOverflowquestionchecklist关闭9年前。Improvethisquestion我正在从我的用户那里收集尺码信息,因此当他们查看主产品页面时,他们只会看到符合其尺码的产品。我认为解决方案涉及产品范围,但我不确定如何实现。任何人对实现此目标的最佳方式有任何想法吗?

ruby-on-rails - correct_user 不使用 current_user?

我希望未登录的人能够看到展示页面。现在他们收到current_user的NoMethodError错误。defshow@correct_user=current_user.challenges.find_by(id:params[:id])endsessions_helper#Returnsthecurrentlogged-inuser(ifany).defcurrent_userif(user_id=session[:user_id])@current_user||=User.find_by(id:user_id)elsif(user_id=cookies.signed[:user_

ruby-on-rails - current_user.present 和 if user_signed_in 有什么区别?

正在设计并想知道两者之间的区别是什么和 最佳答案 不,实际上没有区别。查看user_signed_in?的元编程实现:def#{mapping}_signed_in?!!current_#{mapping}end当针对User模型进行身份验证时,这解析为:defuser_signed_in?!!current_userend注意:如果current_user为nil或false,则!!current_user返回true>。这与present?完全相同 关于ruby-on-rails-c

ruby-on-rails - 教程 Michael Hartl 在 9.3 上访问 edit_user_path 失败

我有一个我无法解决的错误。我按照教程中的步骤操作,但无法通过绿色测试。我遇到了这个错误:$bundleexecrspecspec/requests/user_pages_spec.rb-e"Editpage"Runoptions:include{:full_description=>/Edit\page/}FFFFailures:1)UserpagesEditpageFailure/Error:before{visitedit_user_path(user)}ActionView::Template::Error:undefinedmethod`model_name'forNilCla

ruby-on-rails - ruby rails : redirect unauthenticated user to root instead of the sign in page

我正在使用Rails4和Devise3。我在路由文件中使用以下内容来防止未经身份验证的用户(未登录)访问页面:authenticate:userdo#pagetoprotectend这会将我重定向到用户/登录页面,但我希望将用户重定向到根目录。因此,我还在路由页面中添加了以下内容:get'user/sign_in'=>redirect('/')但这会弄乱我在session_controllers中所做的事情:defnewreturnrender:json=>{:success=>false,:type=>"signinn",:errors=>["Youhavetoconfirmyour

ruby-on-rails - 注册时以嵌套形式传递 user_id 并保存两个模型

我的Devise注册表单上有一个嵌套表单,它填充了一个连接表。连接表信息未保存,因为user_id为nil。这是因为他们还没有登录,所以我不能通过current_user。如何通过user_id以一种形式保存连接表(语言用户)?new.html.erb的相关部分registrations_controller.rbclassUsers::RegistrationsController这是我的参数:{"utf8"=>"✓","authenticity_token"=>"v/uM0+B7/XCUKmhyFGoEKqunCllXAK50uZN5f+TDpUsxlnIsgQVPbXhEb1q1

ruby - 使用 RSpec 测试 @current_user 方法

这几天我一直在尝试这样做,但我无法弄清楚。我的Controller中有以下代码:@some_object=@current_user.some_method在我的规范中,我想在那个方法上附加一个should_receiveHook,但我无法让它工作。我已经尝试了所有这些,但都没有用:assigns[:current_user].should_receive(:some_method).at_least(:once)#expected1,got0User.should_receive(:some_method).at_least(:once)#expected1,got0正确的测试方法是

ruby - #<ActiveRecord::Relation:0x007f8da82da248> 的未定义方法 `user_id'

我在此处代码的第2行出错,我在Estate表中有一列user_id。我在这里做错了什么?myestate=Estate.where(:Mgmt=>current_user.Company)@managements=User.where(:id=>myestate.user_id) 最佳答案 where返回ActiveRecord::Relation目的。因为where(:mgmt=>current_user.company)可能返回0、1或许多记录,所以您必须告诉查询您想要从中得到什么。尝试:myestate=Estate.wher