02-11-2011, 03:42 PM
(Modification du message : 02-11-2011, 03:59 PM par Sephi-Chan.)
En gros :
Et la vue :
En fait je vire l'archive, ces fragments suffisent.
class MessagesController < ApplicationController
def new
@message = Message.new
end
def create
receiver_name = params.delete(:receiver_name)
@message = Message.new(params[:message])
@message.receiver = User.find_by_name(receiver_name)
if @message.save
redirect_to @message
else
render :new
end
end
end
Et la vue :
= form_for @message do |f|
%p
= label_tag :receiver_name
= text_field_tag :receiver_name, f.object.receiver.try(:name)
= errors_for(f.object, :receiver_name)
%p
= f.label :content
= f.text_area :content
= errors_for(f.object, :content)
%p
= f.submit
En fait je vire l'archive, ces fragments suffisent.