如何使编辑用户页面在我的主页上运行?
完全的 Rails 新手,有些东西就是不灵光。
在我的主页 /home - 我使用 devise,所以我有一个 check 。
<% if user_signed_in? %>
<%= render "getting_started" %>
<% else %>
Welcome!
<%= link_to "Sign up", new_user_registration_path%>
<% end %>
目前 getting_started.html.erb 有一些说明,然后我显示 /users/_getting_started_form.html.erb。
该表单中已经包含了模型中的一些额外字段(例如,用户名,我希望用户在使用电子邮件/密码登录后进行设置,并使用 <%= form_for(@user) do 呈现|f| %>
.. 一旦我将
@user = :current_user
.. 放入 PagesController 的 home 方法中,它就不会出现错误,但我想发布到用户控制器。表单来获取输入的数据,将其发布到用户控制器,并将数据保存到模型中。
对于造成的混乱,抱歉,对于rails自动化的事情来说,事情是没有意义的——对我来说,问题的一部分在于PHP 我只是自己将一个表单发布到适当的控制器,并且还设计了 - 我投入其中以快速正确完成用户身份验证并没有为我创建用户控制器,我发现注册等非常令人困惑. 在没有名为 UsersController 的文件的情况下,我(显然)对这个和 Rails 中的最佳方法感到非常困惑 - 非常感谢。
Complete rails novice and something just isn't clicking.
On my home page /home - I use devise, so I have a check .
<% if user_signed_in? %>
<%= render "getting_started" %>
<% else %>
Welcome!
<%= link_to "Sign up", new_user_registration_path%>
<% end %>
At the moment getting_started.html.erb has some instructions and then I'm displaying /users/_getting_started_form.html.erb.
The form is there with some extra fields already catered for in the model (eg. username, which I'd like users to set once they've logged in with email/password, rendered with <%= form_for(@user) do |f| %>
.. and it renders without error once I put:
@user = :current_user
..into the home method of PagesController. But that's not right is it? I'd want to be posting to the users controller. I want the getting started form to take the data entered, post it to the users controller, and save the data to the model.
Sorry for the confusion, things just aren't making sense with the amount of things rails automates - part of the issue for me is in PHP I'd just post a form to the appropriate controller myself, and also devise - which I plunged in to get user authentication done properly quickly doesn't create a users controller for me, which I find that very confusing that sign up, etc. works without a file named UsersController being there. I'm (clearly) very confused on this and best approaches in rails. - Help very much appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为什么
:current_user
?这是一个符号,并不指向任何User
对象。也许您所追求的只是current_user
?Why
:current_user
? That's a symbol and doesn't point to anyUser
object. Perhaps what you're after is simplycurrent_user
?