/user/profile 处出现 NoMethodError - 未定义方法“更新” for nil:NilClass - 使用 DataMapper 的 Sinatra 应用程序

发布于 2024-10-29 01:35:59 字数 1064 浏览 0 评论 0原文

您好,我在使用 Sinatra 应用程序时遇到旋转错误。我正在使用 DataMapper 1.1 和 Ruby 1.9.2-p136。在在这里寻求帮助之前,我已经进行了详尽的搜索和破解。

我质疑/尝试过的事情: 如果 DataMapper #update 不创建新记录(如果不存在),如何创建新用户? 所以我尝试了first_or_create,但没有解决问题。 这是我添加了 except create 的时候。 我已经对此进行了三天的调试,并且我绝对愿意重构。事实上,我肯定会进行重构,但我想首先解决这个问题,以便我从错误中吸取教训。具体来说,我不想使用“除非”代码,并且我觉得有更好的方法来编写 /after_login 部分。

我一直在 irc #datamapper #sinatra #ruby 上露营——尽管已经进行了慷慨的尝试,但还没有运气。

最后,原始代码与 DataMapper 0.9 一起工作,这让我认为这是一个 DM 问题,但我现在认为情况可能并非如此。

非常感谢任何帮助!

要点:

git://gist.github.com/897342.git -- ruby​​ app 文件 -- 添加了 except create (我觉得这有很多问题)

git://gist.github.com/895532.git -- ruby​​ 应用程序文件 -- 在被黑客尝试添加创建调用

git://gist.github.com/895394.git 之前 -- user.rb 文件

git://gist.github.com/895391.git -- 错误回溯

=== 更新: 经过数小时的代码争论等,以及来自 irc 小组 #datamapper #sinatra 和 #ruby 的巨大帮助!感谢所有帮助过的人,尤其是 Dkubb! 我很高兴地报告,我已经清除了 NoMethodErrors,现在正在处理其他一些问题,主要是了解我的所有代码到底在做什么、更忠实的测试以及一般的整体重构。

我会持续更新这个内容,供有兴趣的人参考。

一般的解决方法是将我的方法和类分开,这样我就知道调用了什么、为什么以及如何调用。具体来说,@user 造成了很多问题。所以西纳特拉的错误在于诚实。 ;-)

Hi I am getting rotating errors with a Sinatra App. I am using DataMapper 1.1 and Ruby 1.9.2-p136. I have searched and hacked exhaustingly prior to seeking assistance here.

Things I've questioned/tried:
How is a new user being created if DataMapper #update doesn't create new record if it doesn't exist?
So I tried first_or_create which didn't solve the issue.
This is when I added the unless create.
I have been debugging this for 3 days and I am definitely open to a refactor. In fact I will for sure do a refactor however I want to get this resolved first so that I learn from the mistakes. Specifically I don't want to use the "unless" codes and I feel there's a much better way of writing the /after_login section.

I have been camping on irc #datamapper #sinatra #ruby -- although there've been generous attempts, no luck yet.

Lastly, the original code worked with DataMapper 0.9 which made me think it was a DM issue, however I think now that might not be the case.

Any help is greatly appreciated!

Gists:

git://gist.github.com/897342.git
-- ruby app file -- added the unless create (I feel that this has a lot of problems)

git://gist.github.com/895532.git
-- ruby app file -- before hacked attempt to add create call

git://gist.github.com/895394.git
-- user.rb file

git://gist.github.com/895391.git
-- error backtrace

=== update:
After many hours of code wrangling and such and the great help from the irc groups #datamapper #sinatra and #ruby !! thanks to all that helped especially Dkubb!
I am semi-happy to report that I've cleared out the NoMethodErrors and am now on to some other issues, mainly knowing what exactly all of my code is doing, more faithful testing, and a general overall refactor.

I will keep updating this for those who are interested.

The general fix was to separate my methods and classes so I know what's being called, why, and how. Specifically @user was causing quite a few problems. So Sinatra error was being truthful. ;-)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文