LoginSignup
38
34

More than 5 years have passed since last update.

namespace配下でform_forを使う方法

Posted at

ルータでnamespaceを区切ったコントローラでform_forを使う場合、form_forが期待するリクエスト先URLにnamespace名を挟むには以下のように書けば良い。

(ex exampleモデルを扱うdashboard/examplesコントローラの場合

config/routes.rb
namespace 'dashbord' do
  resources :examples
end
controller/dashboard/examples_controller.rb
class Dashboard::ExampleController < ApplicationController

  def new
    @example = Example.new
  end

  

end
view/dashboard/examples/_form.html.erb
<%= form_for [:dashboard, @example] do |f| %>
38
34
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
38
34