How do I pass object values with render :action => 'new'
Posted
by PlanetMaster
on Stack Overflow
See other posts from Stack Overflow
or by PlanetMaster
Published on 2010-05-25T09:22:48Z
Indexed on
2010/05/25
9:41 UTC
Read the original article
Hit count: 149
ruby-on-rails
Hi,
In an app I have the following:
def new
@property = Property.new(:country_id => 1, :user_id => current_user.id, :status_id => 'draft')
end
def create
@property = Property.new(params[:property])
if @property.save
flash[:success] = t('The_property_is_successfully_created')
redirect_to myimmonatie_url
else
flash.now[:error]=t("The_property_could_not_be_created")
render :action => 'new'
end
end
When an error accors, the line render :action => 'new' gets executed, but the my form gives an error: user blank country blank These cannot be blank (defined in model), meaning this code:
@property = Property.new(:country_id => 1, :user_id => current_user.id, :status_id => 'draft')
is not executed anymore. What is the reason and solution?
Thanks!
© Stack Overflow or respective owner