Dwa kontrolery

Witam mam dwa kontrolery
1:

[code=“ruby”]class ProfilesController < ApplicationController

def new
@profile = User.new

respond_to do |format|
  format.html
end

end

def create
@profile = User.new(params[:user])

respond_to do |format|
  if @profile.save
    flash[:notice] = "Registration successful."
    format.html {redirect_to(login_url)}
  else
    format.html {render :action => "new"}
  end
end

end
…[/code]
kontroler 2

[code=“ruby”]class UsersController < ApplicationController

def create
@user = User.new(params[:user])

respond_to do |format|
  if @user.save
    flash[:notice] = "Registration successful."
    format.html {redirect_to(login_url)}
  else
    format.html {render :action => "new"}
  end
end

end
…[/code]
Wchodzę w profile/new, otwiera sie formularz dodawania nowego profilu. Klikam “create profile” i zamiast wykonać się create z kontrolera profile , wykonuje sie create z kontrolera user.
Dlaczego tak się dzieje? Czy to jakiś błąd?

EDIT:
A może to przez to że w kontrolerze profile mam :
@profile = User.new
zamiast
@profile = Profile.new

W ogóle nie mam w bazie tabeli profile tylko user. A chciałem aby dla usera wyświetlał się adres …/profiles/2 a dla administratora /users/2.

Pozdrawiam

Bez routesów i widoków ciężko cokolwiek powiedzieć. Wklej tutaj routesy i profile/new.html.erb

routes

[code=“ruby”]ActionController::Routing::Routes.draw do |map|
map.login ‘login’, :controller => ‘user_sessions’, :action => ‘new’
map.logout ‘logout’, :controller => ‘user_sessions’, :action => ‘destroy’
map.register ‘register’, :controller => ‘users’, :action => ‘new’

map.resources :categories
map.resources :makers
map.resources :managers
map.resources :developments, :member => {:download => :get}, :has_many => :requests
map.resources :requests

map.resources :profiles
map.resources :users
map.resources :user_sessions
map.resources :roles

map.root :controller => ‘user_sessions’, :action => ‘new’

map.connect ‘:controller/:action/:id’
map.connect ‘:controller/:action/:id.:format’
end[/code]
profile/new

[code=“ruby”]- title t(:profiles_new_profile_title)

%h1= yield :title

  • form_for @profile, :html => {:class => nil, :id => ‘profile_form’} do |f|
    = f.error_messages :header_message => nil, :class => nil, :id => ‘form_error_message’, :message => t(:profiles_new_profile_error)

    #form_body
    %p
    = f.label :surname, t(:profiles_surname_label)
    = f.text_field :surname, :autocomplete => ‘off’, :maxlength => ‘16’, :size => ‘20’
    %p
    = f.label :forename, t(:profiles_forename_label)
    = f.text_field :forename, :autocomplete => ‘off’, :maxlength => ‘12’, :size => ‘16’
    %p
    = f.label :email, t(:profiles_email_label)
    = f.text_field :email, :autocomplete => ‘off’, :maxlength => ‘40’, :size => ‘44’
    %p
    = f.label :password, t(:profiles_password_label)
    = f.password_field :password, :maxlength => ‘16’, :size => ‘20’
    %p
    = f.label :password_confirmation, t(:profiles_password_confirmation_label)
    = f.password_field :password_confirmation, :maxlength => ‘16’, :size => ‘20’

    #form_buttons
    %p= f.submit t(:profiles_create_button), :id => ‘button_right’[/code]

A może to przez to że w kontrolerze profile mam :
@profile = User.new
zamiast
@profile = Profile.new

W ogóle nie mam w bazie tabeli profile tylko user. A chciałem aby dla usera wyświetlał się adres …/profiles/2 a dla administratora /users/2.

Pozdrawiam

[quote=l0pez]A może to przez to że w kontrolerze profile mam :
@profile = User.new
zamiast
@profile = Profile.new[/quote]
Tak, w form_for masz generowanie adresu z obiektu.

Dodaj tam :url => users_path i będzie ok.

Zmieniełem

  • form_for @profile, :html => {:class => nil, :id => ‘profile_form’} do |f|
    na
  • form_for @profile, :url => profiles_path, :html => {:class => nil, :id => ‘profile_form’} do |f|

ale nie pomogło. Nadal to samo.

Pozdrawiam

OK, działa dzięki, zmieniłem jeszcze w routesach:
map.register ‘register’, :controller => ‘users’, :action => ‘new’
na map.register ‘register’, :controller => ‘profiles’, :action => ‘new’

A tak swoją drogą, dlaczego z nie działa to bez :url bo nie rozumiem.