Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I pass object values with render :action => 'new'
    text
    copied!<p>In an app I have the following:</p> <pre><code> def new @property = Property.new(:country_id =&gt; 1, :user_id =&gt; current_user.id, :status_id =&gt; '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 =&gt; 'new' end end </code></pre> <p>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:</p> <pre><code>@property = Property.new(:country_id =&gt; 1, :user_id =&gt; current_user.id, :status_id =&gt; 'draft') </code></pre> <p>is not executed anymore. What is the reason and solution?</p> <p>UPDATE: The view is very long, but the relevant lines are these:</p> <pre><code>&lt;% form_for :property, @property, :url =&gt; { :action =&gt; "create" } do |f| %&gt; &lt;%= f.error_messages( :header_message =&gt; nil, :message =&gt; nil) %&gt; &lt;!--lot's of fields --&gt; &lt;%- end -%&gt; </code></pre> <p>The app does not crash, it is the error_messages that show the fields that cannot be blank. The first 2 answers already gave me the reason for the error: the render new does not execute the new method, so it is logical that the paramters are empty. The goal is now to make sure that the view also reveices the parameters that are also set in the new method. How to achieve that?</p> <p>Thanks!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload