[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
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.
[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.