Rails 3: Странная ошибка перенаправления устройства

Итак, у меня возникла интересная проблема. Я пытаюсь переопределить и перенаправить запрос sign_up и sign_in на соответствующие страницы профиля, но сталкиваюсь с ошибкой. Профили и URL-адрес работают при доступе к ним с помощью консоли, link_to или путем ввода. По какой-то причине метод devise не будет направляться к нему. Я не уверен, почему. В любом случае, голосуйте за всех, кто вносит свой вклад или решает. Спасибо!

Маршруты:

  root :to => 'pages#index'
  get "pages/index"

  devise_for :users, :path => 'accounts', :controllers => { :registrations => "registrations" }

  get 'users/:id/profile' => 'profiles#show', :as => 'current_profile'
  get 'users/:id/profile/edit' => 'profiles#edit', :as => 'edit_current_profile'
  put 'users/:id/profile' => 'profiles#update'

  resources :users do
    resources :profiles 
  end

Контроллер регистрации:

class RegistrationsController < Devise::RegistrationsController

  protected

  def after_sign_up_path_for(resource)
     edit_current_profile_path(resource)
  end

  def after_sign_in_path_for(resource)
     current_profile_path(resource)
  end

end

Контроллер профиля

  def show
    @user = current_user
    @profile = @user.profile

    respond_to do |format|
      format.html 
    end
  end

Сообщение об ошибке:

Routing Error

No route matches {:controller=>"profiles", :action=>"show"}
Try running rake routes for more information on available routes.

Просмотр: edit.html.erb

<%= form_for([@profile.user, @profile]) do |f| %>
  <% if @profile.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(@profile.errors.count, "error") %> prohibited this profile from being saved:</h2>

      <ul>
      <% @profile.errors.full_messages.each do |msg| %>
        <li><%= msg %></li>
      <% end %>
      </ul>
    </div>
  <% end %>

  <div class="field">
    <%= f.label :real_name %><br />
    <%= f.text_field :real_name %>
  </div>
  <div class="actions">
    <%= f.submit %>
  </div>
<% end %>

person jbearden    schedule 13.09.2012    source источник


Ответы (1)


Вы должны дать атрибут вашим помощникам маршрута. Попробуйте

def after_sign_up_path_for(resource)
   edit_current_profile_path(resource)
end

def after_sign_in_path_for(resource)
   current_profile_path(resource) 
end
person Nick Kugaevsky    schedule 13.09.2012
comment
Спасибо за ответ. Теперь я добавил атрибуты, но все та же ошибка - person jbearden; 13.09.2012
comment
Это может быть вызвано помощниками маршрута в вашем представлении. Можете ли вы добавить страницу редактирования профиля к вашему вопросу? - person Nick Kugaevsky; 13.09.2012
comment
Хорошо. Только что обновил. Это странно, потому что я могу обновить профиль для разных пользователей, если я вручную перейду к URL-адресам. - person jbearden; 13.09.2012
comment
Ничего криминального здесь не нашел, извините. Все еще думаю, что эта ошибка вызвана неверным помощником маршрута. Что-то вроде profile_path вместо user_profile_path. - person Nick Kugaevsky; 13.09.2012
comment
Поэтому я изменил get to match, и он перестает выдавать мне ошибку! Спасибо за ответ. - person jbearden; 13.09.2012