LoginSignup
9
4

More than 5 years have passed since last update.

【Devise】form_for内の「url: session_path」「url: registration_path」ってなんだよ?!

Last updated at Posted at 2019-01-18

でたぞ不明点。

devise/registration/edit.html.erb
<%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %>
  <%= render "devise/shared/error_messages", resource: resource %>

  <div class="field">
    <%= f.label :email %><br />
    <%= f.email_field :email, autofocus: true, autocomplete: "email" %>

 (中略)

    <%= f.submit "Update" %>
  </div>
<% end %>

<p>Unhappy? <%= button_to "Cancel my account", registration_path(resource_name), data: { confirm: "Are you sure?" }, method: :delete %></p>

<%= link_to "Back", :back %>


deviseのregistration、session等のnewやeditにはform_forが入っていて、
そのurlオプションにprefixパスが使われているが(上記コードだと上から1行目と下から3行目)、
rails routesをしてもこのprefixが見つからない。

てなわけで調べたら、案外あっさりのお味噌汁だた。

参考:Devise's registration_path, how it's generated?
https://stackoverflow.com/questions/19645698/devises-registration-path-how-its-generated

Devise::Controllers::UrlHelpersにて、self.generate_helpers!というメソッドで規定しているらしい。
コードも見たけど、prefixパスはmethod = "#{action}#{module_name}_#{path_or_url}"部分で作ってるんだろな。


てなわけで終了。
1R 2分3秒(メイウェザー VS 那須川より16秒早い)

9
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
4