Note that there are some explanatory texts on larger screens.

plurals
  1. POPassing parameter in URL and then rendering errors with 'new' action if validation not passed
    primarykey
    data
    text
    <p>I have encountered issue that I suspect is not that hard to fix and simply my lack of experience is making it hard. </p> <p>I have my route </p> <pre><code>match '(/:client_id)/signup', to: 'users#new' </code></pre> <p>Now if client is sending link to whoever www.myappurl.com/123/signup the user will signup and his user model will receive client_id as parameter (which I need later on). </p> <p>Controller: </p> <pre><code>def new @user = User.new if signed_in? redirect_to root_path end end def create @user = User.new(params[:user]) if @user.save sign_in @user flash[:success] = t("users.new.welcome") redirect_to @user else render 'new' #and this is the problem end end </code></pre> <p>And the problem is, that when users submits his application, and information he provides doesn't pass the validation then 'new' action is rendered but I loose this :client_id parameter and therefore association between him and client. </p> <p>I have tried redirect_to and passing params. This works, but error messages are not displayed.</p> <p>Any ideas how to fix it? </p> <p>EDIT</p> <p>my debug before submitting invalid info: </p> <pre><code>controller: users action: new locale: en client_id: '2' </code></pre> <p>and after:</p> <pre><code>!binary "dXRmOA==": ✓ !binary "YXV0aGVudGljaXR5X3Rva2Vu": ldtdjuWAWHB052qY3ASoH1Mv3XYtrdRcL56DgSaYC0Q= !binary "dXNlcg==": !ruby/hash:ActiveSupport::HashWithIndifferentAccess !binary "Zmlyc3RfbmFtZQ==": '' !binary "bGFzdF9uYW1l": '' !binary "ZW1haWw=": '' !binary "Y2xpZW50X2lk": '2' !binary "cGFzc3dvcmQ=": '' !binary "cGFzc3dvcmRfY29uZmlybWF0aW9u": '' !binary "Y29tbWl0": Create my account action: create controller: users locale: en </code></pre> <p>SERVER LOG</p> <pre><code>Started POST "/en/users" for 127.0.0.1 at 2012-10-16 07:10:31 +0800 Processing by UsersController#create as HTML Parameters: {"utf8"=&gt;"✓", "authenticity_token"=&gt;"ldtdjuWAWHB052qY3ASoXYtrdRcL56DgSaYC0Q=", "user"=&gt;{"first_name"=&gt;"", "last_name"=&gt;"", "email"=&gt;"", "client_id"=&gt;"2", "password"=&gt;"[FILTERED]", "password_confirmation"=&gt;"[FILTERED]"}, "commit"=&gt;"Create my account", "locale"=&gt;"en"} (0.4ms) BEGIN User Exists (2.5ms) SELECT 1 AS one FROM "users" WHERE LOWER("users"."email") = LOWER('') LIMIT 1 (0.1ms) ROLLBACK Rendered shared/_error_messages.html.erb (18.6ms) Rendered users/_fields_for_registration_no_verification.html.erb (36.9ms) Rendered users/_password_fields.html.erb (3.6ms) Rendered users/new.html.erb within layouts/application (77.5ms) Rendered layouts/_shim.html.erb (0.0ms) Rendered layouts/_google_tracking_code (0.0ms) User Load (2.4ms) SELECT "users".* FROM "users" WHERE "users"."remember_token" IS NULL LIMIT 1 Rendered layouts/_header.html.erb (8.7ms) Rendered layouts/_footer.html.erb (1.5ms) Completed 200 OK in 437ms (Views: 213.4ms | ActiveRecord: 14.9ms) </code></pre> <p>EDIT</p> <p>I have found real source of the problem (different from answer below). Issue was that when I was using hidden field in my form I was using following code: </p> <pre><code>&lt;%= f.hidden_field :client_id, { :value =&gt; params[:client_id]} %&gt; </code></pre> <p>It turned out that once I deleted the <code>{ :value =&gt; params[:client_id]}</code> part everything started to work as expected after unsuccessful registration. Never the less thanks for help. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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