rubyrookie
2012-Dec-10 05:53 UTC
Values not being being reflected on page after validation error but model has the values
I have a relationship where a merchant can have multiple payments. I am posting payments to a merchant and there is a validation error. Payment object does have the values retained. Can some one help me fix the issue? View Code-> <%= @merchant.name %> <%= form_for([@merchant, @merchant.payments.build]) do |f| %> <% if @payment.errors.any? %> <div id="error_explanation"> <h2><%= pluralize(@payment.errors.count, "error") %> prohibited this payment from being saved:</h2> <ul> <% @payment.errors.full_messages.each do |msg| %> <li> <%= msg %> </li> <% end %> </ul> </div> <% end %> test // Prints the values correctly <%= @payment.credit_card_number %> <%= @payment.zip %> <%= @payment.country %> <div class="field"> <%= f.label :credit_card_number %> <br /> <%= f.text_field :credit_card_number , :autocomplete => "off" %> </div> <div class="field"> <%= f.label :address_line_2 %> <br /> <%= f.text_field :address_line_2 %> </div> <div class="field"> <%= f.label :city %> <br /> <%= f.text_field :city %> </div> <div class="field"> <%= f.label :zip %> <br /> <%= f.text_field :zip %> </div> <div class="field"> <%= f.label :country %> <br /> <%= f.text_field :country %> </div> <div class="actions"> <%= f.submit %> </div> <% end %> Controller code-> class PaymentsController < ApplicationController # GET /merchants/1 # GET /merchants/1.json def new @payment = Payment.new @merchant = Merchant.find(params[:merchant_id]) respond_to do |format| format.html # show.html.erb end end def index if params[:merchant_id] @payments = Merchant.find(params[:merchant_id]).payments else @payments = Payment.all end respond_to do |format| format.html # index.html.erb format.json { render json: @merchants } end end def create @merchant = Merchant.find(params[:merchant_id]) @payment = @merchant.payments.create(params[:payment]) respond_to do |format| if @merchant.save format.html {redirect_to merchants_path} else format.html { render action: "new" } end end end end -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/PTxFOGJob9sJ. For more options, visit https://groups.google.com/groups/opt_out.
Jim Ruther Nill
2012-Dec-10 05:57 UTC
Re: Values not being being reflected on page after validation error but model has the values
On Mon, Dec 10, 2012 at 1:53 PM, rubyrookie <asajnani-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I have a relationship where a merchant can have multiple payments. I am > posting payments to a merchant and there is a validation error. Payment > object does have the values retained. Can some one help me fix the issue? > > View Code-> > > <%= @merchant.name %> > > <%= form_for([@merchant, @merchant.payments.build]) do |f| %> > > <% if @payment.errors.any? %> > <div id="error_explanation"> > <h2><%= pluralize(@payment.errors.count, "error") %> prohibited this > payment from being saved:</h2> > > <ul> > <% @payment.errors.full_messages.each do |msg| %> > <li> > <%= msg %> > </li> > <% end %> > </ul> > </div> > <% end %> > > test > // Prints the values correctly > <%= @payment.credit_card_number %> > <%= @payment.zip %> > <%= @payment.country %> > > <div class="field"> > <%= f.label :credit_card_number %> > <br /> > <%= f.text_field :credit_card_number , :autocomplete => "off" %> > </div> > <div class="field"> > <%= f.label :address_line_2 %> > <br /> > <%= f.text_field :address_line_2 %> > </div> > <div class="field"> > <%= f.label :city %> > <br /> > <%= f.text_field :city %> > </div> > <div class="field"> > <%= f.label :zip %> > <br /> > <%= f.text_field :zip %> > </div> > <div class="field"> > <%= f.label :country %> > <br /> > <%= f.text_field :country %> > </div> > > <div class="actions"> > <%= f.submit %> > </div> > <% end %> > > Controller code-> > > class PaymentsController < ApplicationController > # GET /merchants/1 > # GET /merchants/1.json > def new > @payment = Payment.new > @merchant = Merchant.find(params[:merchant_id]) > respond_to do |format| > format.html # show.html.erb > end > end > > def index > > if params[:merchant_id] > @payments = Merchant.find(params[:merchant_id]).payments > else > @payments = Payment.all > end > > respond_to do |format| > format.html # index.html.erb > format.json { render json: @merchants } > end > end > > def create > @merchant = Merchant.find(params[:merchant_id]) > @payment = @merchant.payments.create(params[:payment]) > > respond_to do |format| > if @merchant.save > format.html {redirect_to merchants_path} > else > format.html { render action: "new" } > > end > end > > end > > end >what error do you get?> > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To view this discussion on the web visit > https://groups.google.com/d/msg/rubyonrails-talk/-/PTxFOGJob9sJ. > For more options, visit https://groups.google.com/groups/opt_out. > > >-- ------------------------------------------------------------- visit my blog at http://jimlabs.heroku.com -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
rubyrookie
2012-Dec-10 06:26 UTC
Re: Values not being being reflected on page after validation error but model has the values
No error . Validation error is populated but form does not retain values. Payment object has the values though. On Sunday, December 9, 2012 9:53:37 PM UTC-8, rubyrookie wrote:> I have a relationship where a merchant can have multiple payments. I am > posting payments to a merchant and there is a validation error. Payment > object does have the values retained. Can some one help me fix the issue? > > View Code-> > > <%= @merchant.name %> > > <%= form_for([@merchant, @merchant.payments.build]) do |f| %> > > <% if @payment.errors.any? %> > <div id="error_explanation"> > <h2><%= pluralize(@payment.errors.count, "error") %> prohibited this > payment from being saved:</h2> > > <ul> > <% @payment.errors.full_messages.each do |msg| %> > <li> > <%= msg %> > </li> > <% end %> > </ul> > </div> > <% end %> > > test > // Prints the values correctly > <%= @payment.credit_card_number %> > <%= @payment.zip %> > <%= @payment.country %> > > <div class="field"> > <%= f.label :credit_card_number %> > <br /> > <%= f.text_field :credit_card_number , :autocomplete => "off" %> > </div> > <div class="field"> > <%= f.label :address_line_2 %> > <br /> > <%= f.text_field :address_line_2 %> > </div> > <div class="field"> > <%= f.label :city %> > <br /> > <%= f.text_field :city %> > </div> > <div class="field"> > <%= f.label :zip %> > <br /> > <%= f.text_field :zip %> > </div> > <div class="field"> > <%= f.label :country %> > <br /> > <%= f.text_field :country %> > </div> > > <div class="actions"> > <%= f.submit %> > </div> > <% end %> > > Controller code-> > > class PaymentsController < ApplicationController > # GET /merchants/1 > # GET /merchants/1.json > def new > @payment = Payment.new > @merchant = Merchant.find(params[:merchant_id]) > respond_to do |format| > format.html # show.html.erb > end > end > > def index > > if params[:merchant_id] > @payments = Merchant.find(params[:merchant_id]).payments > else > @payments = Payment.all > end > > respond_to do |format| > format.html # index.html.erb > format.json { render json: @merchants } > end > end > > def create > @merchant = Merchant.find(params[:merchant_id]) > @payment = @merchant.payments.create(params[:payment]) > > respond_to do |format| > if @merchant.save > format.html {redirect_to merchants_path} > else > format.html { render action: "new" } > > end > end > > end > > end > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/jSZvC8ID4ycJ. For more options, visit https://groups.google.com/groups/opt_out.
Jim Ruther Nill
2012-Dec-10 07:08 UTC
Re: Re: Values not being being reflected on page after validation error but model has the values
On Mon, Dec 10, 2012 at 2:26 PM, rubyrookie <asajnani-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> No error . Validation error is populated but form does not retain values. > Payment object has the values though. >This is still confusing. What exactly do you want to do? - Show the validation errors on the form page? - Fix the payment process because you don''t know what validations are failing? - retain the values passed by the user when validations fail?> > On Sunday, December 9, 2012 9:53:37 PM UTC-8, rubyrookie wrote: > >> I have a relationship where a merchant can have multiple payments. I am >> posting payments to a merchant and there is a validation error. Payment >> object does have the values retained. Can some one help me fix the issue? >> >> View Code-> >> >> <%= @merchant.name %> >> >> <%= form_for([@merchant, @merchant.payments.build]) do |f| %> >> >> <% if @payment.errors.any? %> >> <div id="error_explanation"> >> <h2><%= pluralize(@payment.errors.**count, "error") %> prohibited this >> payment from being saved:</h2> >> >> <ul> >> <% @payment.errors.full_messages.**each do |msg| %> >> <li> >> <%= msg %> >> </li> >> <% end %> >> </ul> >> </div> >> <% end %> >> >> test >> // Prints the values correctly >> <%= @payment.credit_card_number %> >> <%= @payment.zip %> >> <%= @payment.country %> >> >> <div class="field"> >> <%= f.label :credit_card_number %> >> <br /> >> <%= f.text_field :credit_card_number , :autocomplete => "off" %> >> </div> >> <div class="field"> >> <%= f.label :address_line_2 %> >> <br /> >> <%= f.text_field :address_line_2 %> >> </div> >> <div class="field"> >> <%= f.label :city %> >> <br /> >> <%= f.text_field :city %> >> </div> >> <div class="field"> >> <%= f.label :zip %> >> <br /> >> <%= f.text_field :zip %> >> </div> >> <div class="field"> >> <%= f.label :country %> >> <br /> >> <%= f.text_field :country %> >> </div> >> >> <div class="actions"> >> <%= f.submit %> >> </div> >> <% end %> >> >> Controller code-> >> >> class PaymentsController < ApplicationController >> # GET /merchants/1 >> # GET /merchants/1.json >> def new >> @payment = Payment.new >> @merchant = Merchant.find(params[:**merchant_id]) >> respond_to do |format| >> format.html # show.html.erb >> end >> end >> >> def index >> >> if params[:merchant_id] >> @payments = Merchant.find(params[:**merchant_id]).payments >> else >> @payments = Payment.all >> end >> >> respond_to do |format| >> format.html # index.html.erb >> format.json { render json: @merchants } >> end >> end >> >> def create >> @merchant = Merchant.find(params[:**merchant_id]) >> @payment = @merchant.payments.create(**params[:payment]) >> >> respond_to do |format| >> if @merchant.save >> format.html {redirect_to merchants_path} >> else >> format.html { render action: "new" } >> >> end >> end >> >> end >> >> end >> >> -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To view this discussion on the web visit > https://groups.google.com/d/msg/rubyonrails-talk/-/jSZvC8ID4ycJ. > > For more options, visit https://groups.google.com/groups/opt_out. > > >-- ------------------------------------------------------------- visit my blog at http://jimlabs.heroku.com -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
rubyrookie
2012-Dec-10 07:16 UTC
Re: Re: Values not being being reflected on page after validation error but model has the values
On Sunday, December 9, 2012 11:08:57 PM UTC-8, jim wrote:> > > > > On Mon, Dec 10, 2012 at 2:26 PM, rubyrookie <asaj...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org<javascript:> > > wrote: > >> No error . Validation error is populated but form does not retain values. >> Payment object has the values though. >> > > This is still confusing. What exactly do you want to do? > > - Show the validation errors on the form page? -> Yes, it is being > displayed > - Fix the payment process because you don''t know what validations are > failing? No, I know the validations are failing > - retain the values passed by the user when validations fail? Yes. The > form is not displayed the retained values. I want this to be fixed. > > > >> >> On Sunday, December 9, 2012 9:53:37 PM UTC-8, rubyrookie wrote: >> >>> I have a relationship where a merchant can have multiple payments. I am >>> posting payments to a merchant and there is a validation error. Payment >>> object does have the values retained. Can some one help me fix the issue? >>> >>> View Code-> >>> >>> <%= @merchant.name %> >>> >>> <%= form_for([@merchant, @merchant.payments.build]) do |f| %> >>> >>> <% if @payment.errors.any? %> >>> <div id="error_explanation"> >>> <h2><%= pluralize(@payment.errors.**count, "error") %> prohibited this >>> payment from being saved:</h2> >>> >>> <ul> >>> <% @payment.errors.full_messages.**each do |msg| %> >>> <li> >>> <%= msg %> >>> </li> >>> <% end %> >>> </ul> >>> </div> >>> <% end %> >>> >>> test >>> // Prints the values correctly >>> <%= @payment.credit_card_number %> >>> <%= @payment.zip %> >>> <%= @payment.country %> >>> >>> <div class="field"> >>> <%= f.label :credit_card_number %> >>> <br /> >>> <%= f.text_field :credit_card_number , :autocomplete => "off" %> >>> </div> >>> <div class="field"> >>> <%= f.label :address_line_2 %> >>> <br /> >>> <%= f.text_field :address_line_2 %> >>> </div> >>> <div class="field"> >>> <%= f.label :city %> >>> <br /> >>> <%= f.text_field :city %> >>> </div> >>> <div class="field"> >>> <%= f.label :zip %> >>> <br /> >>> <%= f.text_field :zip %> >>> </div> >>> <div class="field"> >>> <%= f.label :country %> >>> <br /> >>> <%= f.text_field :country %> >>> </div> >>> >>> <div class="actions"> >>> <%= f.submit %> >>> </div> >>> <% end %> >>> >>> Controller code-> >>> >>> class PaymentsController < ApplicationController >>> # GET /merchants/1 >>> # GET /merchants/1.json >>> def new >>> @payment = Payment.new >>> @merchant = Merchant.find(params[:**merchant_id]) >>> respond_to do |format| >>> format.html # show.html.erb >>> end >>> end >>> >>> def index >>> >>> if params[:merchant_id] >>> @payments = Merchant.find(params[:**merchant_id]).payments >>> else >>> @payments = Payment.all >>> end >>> >>> respond_to do |format| >>> format.html # index.html.erb >>> format.json { render json: @merchants } >>> end >>> end >>> >>> def create >>> @merchant = Merchant.find(params[:**merchant_id]) >>> @payment = @merchant.payments.create(**params[:payment]) >>> >>> respond_to do |format| >>> if @merchant.save >>> format.html {redirect_to merchants_path} >>> else >>> format.html { render action: "new" } >>> >>> end >>> end >>> >>> end >>> >>> end >>> >>> -- >> You received this message because you are subscribed to the Google Groups >> "Ruby on Rails: Talk" group. >> To post to this group, send email to rubyonra...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<javascript:> >> . >> To unsubscribe from this group, send email to >> rubyonrails-ta...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org <javascript:>. >> To view this discussion on the web visit >> https://groups.google.com/d/msg/rubyonrails-talk/-/jSZvC8ID4ycJ. >> >> For more options, visit https://groups.google.com/groups/opt_out. >> >> >> > > > > -- > ------------------------------------------------------------- > visit my blog at http://jimlabs.heroku.com >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/DbPFCiH_y0UJ. For more options, visit https://groups.google.com/groups/opt_out.
Jim Ruther Nill
2012-Dec-10 07:33 UTC
Re: Re: Values not being being reflected on page after validation error but model has the values
On Mon, Dec 10, 2012 at 3:16 PM, rubyrookie <asajnani-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > On Sunday, December 9, 2012 11:08:57 PM UTC-8, jim wrote: > >> >> >> >> On Mon, Dec 10, 2012 at 2:26 PM, rubyrookie <asaj...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >>> No error . Validation error is populated but form does not retain >>> values. Payment object has the values though. >>> >> >> This is still confusing. What exactly do you want to do? >> >> - Show the validation errors on the form page? -> Yes, it is being >> displayed >> - Fix the payment process because you don''t know what validations are >> failing? No, I know the validations are failing >> - retain the values passed by the user when validations fail? Yes. >> The form is not displayed the retained values. I want this to be fixed. >> >>It would''ve helped if you somehow bolded your answers. anyway, you should be able to do that by changing this line <%= form_for([@merchant, @merchant.payments.build]) do |f| %> to <%= form_for([@merchant, @payment]) do |f| %> Good luck!> >> >>> >>> On Sunday, December 9, 2012 9:53:37 PM UTC-8, rubyrookie wrote: >>> >>>> I have a relationship where a merchant can have multiple payments. I am >>>> posting payments to a merchant and there is a validation error. Payment >>>> object does have the values retained. Can some one help me fix the issue? >>>> >>>> View Code-> >>>> >>>> <%= @merchant.name %> >>>> >>>> <%= form_for([@merchant, @merchant.payments.build]) do |f| %> >>>> >>>> <% if @payment.errors.any? %> >>>> <div id="error_explanation"> >>>> <h2><%= pluralize(@payment.errors.**coun**t, "error") %> prohibited >>>> this payment from being saved:</h2> >>>> >>>> <ul> >>>> <% @payment.errors.full_messages.****each do |msg| %> >>>> <li> >>>> <%= msg %> >>>> </li> >>>> <% end %> >>>> </ul> >>>> </div> >>>> <% end %> >>>> >>>> test >>>> // Prints the values correctly >>>> <%= @payment.credit_card_number %> >>>> <%= @payment.zip %> >>>> <%= @payment.country %> >>>> >>>> <div class="field"> >>>> <%= f.label :credit_card_number %> >>>> <br /> >>>> <%= f.text_field :credit_card_number , :autocomplete => "off" %> >>>> </div> >>>> <div class="field"> >>>> <%= f.label :address_line_2 %> >>>> <br /> >>>> <%= f.text_field :address_line_2 %> >>>> </div> >>>> <div class="field"> >>>> <%= f.label :city %> >>>> <br /> >>>> <%= f.text_field :city %> >>>> </div> >>>> <div class="field"> >>>> <%= f.label :zip %> >>>> <br /> >>>> <%= f.text_field :zip %> >>>> </div> >>>> <div class="field"> >>>> <%= f.label :country %> >>>> <br /> >>>> <%= f.text_field :country %> >>>> </div> >>>> >>>> <div class="actions"> >>>> <%= f.submit %> >>>> </div> >>>> <% end %> >>>> >>>> Controller code-> >>>> >>>> class PaymentsController < ApplicationController >>>> # GET /merchants/1 >>>> # GET /merchants/1.json >>>> def new >>>> @payment = Payment.new >>>> @merchant = Merchant.find(params[:**merchant**_id]) >>>> respond_to do |format| >>>> format.html # show.html.erb >>>> end >>>> end >>>> >>>> def index >>>> >>>> if params[:merchant_id] >>>> @payments = Merchant.find(params[:**merchan**t_id]).payments >>>> else >>>> @payments = Payment.all >>>> end >>>> >>>> respond_to do |format| >>>> format.html # index.html.erb >>>> format.json { render json: @merchants } >>>> end >>>> end >>>> >>>> def create >>>> @merchant = Merchant.find(params[:**merchant**_id]) >>>> @payment = @merchant.payments.create(**para**ms[:payment]) >>>> >>>> respond_to do |format| >>>> if @merchant.save >>>> format.html {redirect_to merchants_path} >>>> else >>>> format.html { render action: "new" } >>>> >>>> end >>>> end >>>> >>>> end >>>> >>>> end >>>> >>>> -- >>> You received this message because you are subscribed to the Google >>> Groups "Ruby on Rails: Talk" group. >>> To post to this group, send email to rubyonra...@googlegroups.**com. >>> To unsubscribe from this group, send email to rubyonrails-ta...@** >>> googlegroups.com. >>> To view this discussion on the web visit https://groups.google.com/d/** >>> msg/rubyonrails-talk/-/**jSZvC8ID4ycJ<https://groups.google.com/d/msg/rubyonrails-talk/-/jSZvC8ID4ycJ> >>> . >>> >>> For more options, visit https://groups.google.com/**groups/opt_out<https://groups.google.com/groups/opt_out> >>> . >>> >>> >>> >> >> >> >> -- >> ------------------------------**------------------------------**- >> visit my blog at http://jimlabs.heroku.com >> > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To view this discussion on the web visit > https://groups.google.com/d/msg/rubyonrails-talk/-/DbPFCiH_y0UJ. > > For more options, visit https://groups.google.com/groups/opt_out. > > >-- ------------------------------------------------------------- visit my blog at http://jimlabs.heroku.com -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
rubyrookie
2012-Dec-10 07:42 UTC
Re: Re: Values not being being reflected on page after validation error but model has the values
Thank you very much. I will read up on the difference. Sorry should have bolded my answers. On Sunday, December 9, 2012 11:33:56 PM UTC-8, jim wrote:> > > > > On Mon, Dec 10, 2012 at 3:16 PM, rubyrookie <asaj...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org<javascript:> > > wrote: > >> >> >> On Sunday, December 9, 2012 11:08:57 PM UTC-8, jim wrote: >> >>> >>> >>> >>> On Mon, Dec 10, 2012 at 2:26 PM, rubyrookie <asaj...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >>> >>>> No error . Validation error is populated but form does not retain >>>> values. Payment object has the values though. >>>> >>> >>> This is still confusing. What exactly do you want to do? >>> >>> - Show the validation errors on the form page? -> Yes, it is being >>> displayed >>> - Fix the payment process because you don''t know what validations >>> are failing? No, I know the validations are failing >>> - retain the values passed by the user when validations fail? Yes. >>> The form is not displayed the retained values. I want this to be fixed. >>> >>> > It would''ve helped if you somehow bolded your answers. anyway, you should > be able to do that by > changing this line > > <%= form_for([@merchant, @merchant.payments.build]) do |f| %> > > to > > <%= form_for([@merchant, @payment]) do |f| %> > > Good luck! > > >> >>> >>>> >>>> On Sunday, December 9, 2012 9:53:37 PM UTC-8, rubyrookie wrote: >>>> >>>>> I have a relationship where a merchant can have multiple payments. I >>>>> am posting payments to a merchant and there is a validation error. Payment >>>>> object does have the values retained. Can some one help me fix the issue? >>>>> >>>>> View Code-> >>>>> >>>>> <%= @merchant.name %> >>>>> >>>>> <%= form_for([@merchant, @merchant.payments.build]) do |f| %> >>>>> >>>>> <% if @payment.errors.any? %> >>>>> <div id="error_explanation"> >>>>> <h2><%= pluralize(@payment.errors.**coun**t, "error") %> prohibited >>>>> this payment from being saved:</h2> >>>>> >>>>> <ul> >>>>> <% @payment.errors.full_messages.****each do |msg| %> >>>>> <li> >>>>> <%= msg %> >>>>> </li> >>>>> <% end %> >>>>> </ul> >>>>> </div> >>>>> <% end %> >>>>> >>>>> test >>>>> // Prints the values correctly >>>>> <%= @payment.credit_card_number %> >>>>> <%= @payment.zip %> >>>>> <%= @payment.country %> >>>>> >>>>> <div class="field"> >>>>> <%= f.label :credit_card_number %> >>>>> <br /> >>>>> <%= f.text_field :credit_card_number , :autocomplete => "off" %> >>>>> </div> >>>>> <div class="field"> >>>>> <%= f.label :address_line_2 %> >>>>> <br /> >>>>> <%= f.text_field :address_line_2 %> >>>>> </div> >>>>> <div class="field"> >>>>> <%= f.label :city %> >>>>> <br /> >>>>> <%= f.text_field :city %> >>>>> </div> >>>>> <div class="field"> >>>>> <%= f.label :zip %> >>>>> <br /> >>>>> <%= f.text_field :zip %> >>>>> </div> >>>>> <div class="field"> >>>>> <%= f.label :country %> >>>>> <br /> >>>>> <%= f.text_field :country %> >>>>> </div> >>>>> >>>>> <div class="actions"> >>>>> <%= f.submit %> >>>>> </div> >>>>> <% end %> >>>>> >>>>> Controller code-> >>>>> >>>>> class PaymentsController < ApplicationController >>>>> # GET /merchants/1 >>>>> # GET /merchants/1.json >>>>> def new >>>>> @payment = Payment.new >>>>> @merchant = Merchant.find(params[:**merchant**_id]) >>>>> respond_to do |format| >>>>> format.html # show.html.erb >>>>> end >>>>> end >>>>> >>>>> def index >>>>> >>>>> if params[:merchant_id] >>>>> @payments = Merchant.find(params[:**merchan**t_id]).payments >>>>> else >>>>> @payments = Payment.all >>>>> end >>>>> >>>>> respond_to do |format| >>>>> format.html # index.html.erb >>>>> format.json { render json: @merchants } >>>>> end >>>>> end >>>>> >>>>> def create >>>>> @merchant = Merchant.find(params[:**merchant**_id]) >>>>> @payment = @merchant.payments.create(**para**ms[:payment]) >>>>> >>>>> respond_to do |format| >>>>> if @merchant.save >>>>> format.html {redirect_to merchants_path} >>>>> else >>>>> format.html { render action: "new" } >>>>> >>>>> end >>>>> end >>>>> >>>>> end >>>>> >>>>> end >>>>> >>>>> -- >>>> You received this message because you are subscribed to the Google >>>> Groups "Ruby on Rails: Talk" group. >>>> To post to this group, send email to rubyonra...@googlegroups.**com. >>>> To unsubscribe from this group, send email to rubyonrails-ta...@** >>>> googlegroups.com. >>>> To view this discussion on the web visit https://groups.google.com/d/** >>>> msg/rubyonrails-talk/-/**jSZvC8ID4ycJ<https://groups.google.com/d/msg/rubyonrails-talk/-/jSZvC8ID4ycJ> >>>> . >>>> >>>> For more options, visit https://groups.google.com/**groups/opt_out<https://groups.google.com/groups/opt_out> >>>> . >>>> >>>> >>>> >>> >>> >>> >>> -- >>> ------------------------------**------------------------------**- >>> visit my blog at http://jimlabs.heroku.com >>> >> -- >> You received this message because you are subscribed to the Google Groups >> "Ruby on Rails: Talk" group. >> To post to this group, send email to rubyonra...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<javascript:> >> . >> To unsubscribe from this group, send email to >> rubyonrails-ta...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org <javascript:>. >> To view this discussion on the web visit >> https://groups.google.com/d/msg/rubyonrails-talk/-/DbPFCiH_y0UJ. >> >> For more options, visit https://groups.google.com/groups/opt_out. >> >> >> > > > > -- > ------------------------------------------------------------- > visit my blog at http://jimlabs.heroku.com >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/I6TAroHPoZkJ. For more options, visit https://groups.google.com/groups/opt_out.
Jim Ruther Nill
2012-Dec-10 07:45 UTC
Re: Re: Values not being being reflected on page after validation error but model has the values
On Mon, Dec 10, 2012 at 3:42 PM, rubyrookie <asajnani-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Thank you very much. I will read up on the difference. Sorry should have > bolded my answers.No worries. If you''re looking for the difference, @payment (as you already know) uses the same record as the one you have in your controllers. If you use @merchant.payments.build, you''re creating a new payment record which does not contain the values submitted by the user :)> > > On Sunday, December 9, 2012 11:33:56 PM UTC-8, jim wrote: > >> >> >> >> On Mon, Dec 10, 2012 at 3:16 PM, rubyrookie <asaj...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >>> >>> >>> On Sunday, December 9, 2012 11:08:57 PM UTC-8, jim wrote: >>> >>>> >>>> >>>> >>>> On Mon, Dec 10, 2012 at 2:26 PM, rubyrookie <asaj...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >>>> >>>>> No error . Validation error is populated but form does not retain >>>>> values. Payment object has the values though. >>>>> >>>> >>>> This is still confusing. What exactly do you want to do? >>>> >>>> - Show the validation errors on the form page? -> Yes, it is being >>>> displayed >>>> - Fix the payment process because you don''t know what validations >>>> are failing? No, I know the validations are failing >>>> - retain the values passed by the user when validations fail? Yes. >>>> The form is not displayed the retained values. I want this to be fixed. >>>> >>>> >> It would''ve helped if you somehow bolded your answers. anyway, you should >> be able to do that by >> changing this line >> >> <%= form_for([@merchant, @merchant.payments.build]) do |f| %> >> >> to >> >> <%= form_for([@merchant, @payment]) do |f| %> >> >> Good luck! >> >> >>> >>>> >>>>> >>>>> On Sunday, December 9, 2012 9:53:37 PM UTC-8, rubyrookie wrote: >>>>> >>>>>> I have a relationship where a merchant can have multiple payments. I >>>>>> am posting payments to a merchant and there is a validation error. Payment >>>>>> object does have the values retained. Can some one help me fix the issue? >>>>>> >>>>>> View Code-> >>>>>> >>>>>> <%= @merchant.name %> >>>>>> >>>>>> <%= form_for([@merchant, @merchant.payments.build]) do |f| %> >>>>>> >>>>>> <% if @payment.errors.any? %> >>>>>> <div id="error_explanation"> >>>>>> <h2><%= pluralize(@payment.errors.**coun****t, "error") %> >>>>>> prohibited this payment from being saved:</h2> >>>>>> >>>>>> <ul> >>>>>> <% @payment.errors.full_messages.******each do |msg| %> >>>>>> <li> >>>>>> <%= msg %> >>>>>> </li> >>>>>> <% end %> >>>>>> </ul> >>>>>> </div> >>>>>> <% end %> >>>>>> >>>>>> test >>>>>> // Prints the values correctly >>>>>> <%= @payment.credit_card_number %> >>>>>> <%= @payment.zip %> >>>>>> <%= @payment.country %> >>>>>> >>>>>> <div class="field"> >>>>>> <%= f.label :credit_card_number %> >>>>>> <br /> >>>>>> <%= f.text_field :credit_card_number , :autocomplete => "off" %> >>>>>> </div> >>>>>> <div class="field"> >>>>>> <%= f.label :address_line_2 %> >>>>>> <br /> >>>>>> <%= f.text_field :address_line_2 %> >>>>>> </div> >>>>>> <div class="field"> >>>>>> <%= f.label :city %> >>>>>> <br /> >>>>>> <%= f.text_field :city %> >>>>>> </div> >>>>>> <div class="field"> >>>>>> <%= f.label :zip %> >>>>>> <br /> >>>>>> <%= f.text_field :zip %> >>>>>> </div> >>>>>> <div class="field"> >>>>>> <%= f.label :country %> >>>>>> <br /> >>>>>> <%= f.text_field :country %> >>>>>> </div> >>>>>> >>>>>> <div class="actions"> >>>>>> <%= f.submit %> >>>>>> </div> >>>>>> <% end %> >>>>>> >>>>>> Controller code-> >>>>>> >>>>>> class PaymentsController < ApplicationController >>>>>> # GET /merchants/1 >>>>>> # GET /merchants/1.json >>>>>> def new >>>>>> @payment = Payment.new >>>>>> @merchant = Merchant.find(params[:**merchant****_id]) >>>>>> respond_to do |format| >>>>>> format.html # show.html.erb >>>>>> end >>>>>> end >>>>>> >>>>>> def index >>>>>> >>>>>> if params[:merchant_id] >>>>>> @payments = Merchant.find(params[:**merchan****t_id]).payments >>>>>> else >>>>>> @payments = Payment.all >>>>>> end >>>>>> >>>>>> respond_to do |format| >>>>>> format.html # index.html.erb >>>>>> format.json { render json: @merchants } >>>>>> end >>>>>> end >>>>>> >>>>>> def create >>>>>> @merchant = Merchant.find(params[:**merchant****_id]) >>>>>> @payment = @merchant.payments.create(**para****ms[:payment]) >>>>>> >>>>>> respond_to do |format| >>>>>> if @merchant.save >>>>>> format.html {redirect_to merchants_path} >>>>>> else >>>>>> format.html { render action: "new" } >>>>>> >>>>>> end >>>>>> end >>>>>> >>>>>> end >>>>>> >>>>>> end >>>>>> >>>>>> -- >>>>> You received this message because you are subscribed to the Google >>>>> Groups "Ruby on Rails: Talk" group. >>>>> To post to this group, send email to rubyonra...@googlegroups.**com. >>>>> To unsubscribe from this group, send email to rubyonrails-ta...@** >>>>> googlegroups**.com. >>>>> To view this discussion on the web visit https://groups.google.com/d/* >>>>> *ms**g/rubyonrails-talk/-/**jSZvC8ID4**ycJ<https://groups.google.com/d/msg/rubyonrails-talk/-/jSZvC8ID4ycJ> >>>>> . >>>>> >>>>> For more options, visit https://groups.google.com/**grou**ps/opt_out<https://groups.google.com/groups/opt_out> >>>>> . >>>>> >>>>> >>>>> >>>> >>>> >>>> >>>> -- >>>> ------------------------------****------------------------------****- >>>> visit my blog at http://jimlabs.heroku.com >>>> >>> -- >>> You received this message because you are subscribed to the Google >>> Groups "Ruby on Rails: Talk" group. >>> To post to this group, send email to rubyonra...@googlegroups.**com. >>> To unsubscribe from this group, send email to rubyonrails-ta...@** >>> googlegroups.com. >>> To view this discussion on the web visit https://groups.google.com/d/** >>> msg/rubyonrails-talk/-/**DbPFCiH_y0UJ<https://groups.google.com/d/msg/rubyonrails-talk/-/DbPFCiH_y0UJ> >>> . >>> >>> For more options, visit https://groups.google.com/**groups/opt_out<https://groups.google.com/groups/opt_out> >>> . >>> >>> >>> >> >> >> >> -- >> ------------------------------**------------------------------**- >> visit my blog at http://jimlabs.heroku.com >> > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To view this discussion on the web visit > https://groups.google.com/d/msg/rubyonrails-talk/-/I6TAroHPoZkJ. > > For more options, visit https://groups.google.com/groups/opt_out. > > >-- ------------------------------------------------------------- visit my blog at http://jimlabs.heroku.com -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
Jim Ruther Nill
2012-Dec-10 08:18 UTC
Re: Re: Values not being being reflected on page after validation error but model has the values
On Mon, Dec 10, 2012 at 3:45 PM, Jim Ruther Nill <jvnill-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > > On Mon, Dec 10, 2012 at 3:42 PM, rubyrookie <asajnani-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> Thank you very much. I will read up on the difference. Sorry should have >> bolded my answers. > > > No worries. If you''re looking for the difference, @payment (as you > already know) uses the same > record as the one you have in your controllers. If you use > @merchant.payments.build, you''re > creating a new payment record which does not contain the values submitted > by the user :) >regarding your question on the field_error_proc. read this one and please don''t email users directly :) http://guides.rubyonrails.org/configuring.html#configuring-action-view> > >> >> >> On Sunday, December 9, 2012 11:33:56 PM UTC-8, jim wrote: >> >>> >>> >>> >>> On Mon, Dec 10, 2012 at 3:16 PM, rubyrookie <asaj...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >>> >>>> >>>> >>>> On Sunday, December 9, 2012 11:08:57 PM UTC-8, jim wrote: >>>> >>>>> >>>>> >>>>> >>>>> On Mon, Dec 10, 2012 at 2:26 PM, rubyrookie <asaj...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >>>>> >>>>>> No error . Validation error is populated but form does not retain >>>>>> values. Payment object has the values though. >>>>>> >>>>> >>>>> This is still confusing. What exactly do you want to do? >>>>> >>>>> - Show the validation errors on the form page? -> Yes, it is being >>>>> displayed >>>>> - Fix the payment process because you don''t know what validations >>>>> are failing? No, I know the validations are failing >>>>> - retain the values passed by the user when validations fail? >>>>> Yes. The form is not displayed the retained values. I want this to be >>>>> fixed. >>>>> >>>>> >>> It would''ve helped if you somehow bolded your answers. anyway, you >>> should be able to do that by >>> changing this line >>> >>> <%= form_for([@merchant, @merchant.payments.build]) do |f| %> >>> >>> to >>> >>> <%= form_for([@merchant, @payment]) do |f| %> >>> >>> Good luck! >>> >>> >>>> >>>>> >>>>>> >>>>>> On Sunday, December 9, 2012 9:53:37 PM UTC-8, rubyrookie wrote: >>>>>> >>>>>>> I have a relationship where a merchant can have multiple payments. I >>>>>>> am posting payments to a merchant and there is a validation error. Payment >>>>>>> object does have the values retained. Can some one help me fix the issue? >>>>>>> >>>>>>> View Code-> >>>>>>> >>>>>>> <%= @merchant.name %> >>>>>>> >>>>>>> <%= form_for([@merchant, @merchant.payments.build]) do |f| %> >>>>>>> >>>>>>> <% if @payment.errors.any? %> >>>>>>> <div id="error_explanation"> >>>>>>> <h2><%= pluralize(@payment.errors.**coun****t, "error") %> >>>>>>> prohibited this payment from being saved:</h2> >>>>>>> >>>>>>> <ul> >>>>>>> <% @payment.errors.full_messages.******each do |msg| %> >>>>>>> <li> >>>>>>> <%= msg %> >>>>>>> </li> >>>>>>> <% end %> >>>>>>> </ul> >>>>>>> </div> >>>>>>> <% end %> >>>>>>> >>>>>>> test >>>>>>> // Prints the values correctly >>>>>>> <%= @payment.credit_card_number %> >>>>>>> <%= @payment.zip %> >>>>>>> <%= @payment.country %> >>>>>>> >>>>>>> <div class="field"> >>>>>>> <%= f.label :credit_card_number %> >>>>>>> <br /> >>>>>>> <%= f.text_field :credit_card_number , :autocomplete => "off" %> >>>>>>> </div> >>>>>>> <div class="field"> >>>>>>> <%= f.label :address_line_2 %> >>>>>>> <br /> >>>>>>> <%= f.text_field :address_line_2 %> >>>>>>> </div> >>>>>>> <div class="field"> >>>>>>> <%= f.label :city %> >>>>>>> <br /> >>>>>>> <%= f.text_field :city %> >>>>>>> </div> >>>>>>> <div class="field"> >>>>>>> <%= f.label :zip %> >>>>>>> <br /> >>>>>>> <%= f.text_field :zip %> >>>>>>> </div> >>>>>>> <div class="field"> >>>>>>> <%= f.label :country %> >>>>>>> <br /> >>>>>>> <%= f.text_field :country %> >>>>>>> </div> >>>>>>> >>>>>>> <div class="actions"> >>>>>>> <%= f.submit %> >>>>>>> </div> >>>>>>> <% end %> >>>>>>> >>>>>>> Controller code-> >>>>>>> >>>>>>> class PaymentsController < ApplicationController >>>>>>> # GET /merchants/1 >>>>>>> # GET /merchants/1.json >>>>>>> def new >>>>>>> @payment = Payment.new >>>>>>> @merchant = Merchant.find(params[:**merchant****_id]) >>>>>>> respond_to do |format| >>>>>>> format.html # show.html.erb >>>>>>> end >>>>>>> end >>>>>>> >>>>>>> def index >>>>>>> >>>>>>> if params[:merchant_id] >>>>>>> @payments = Merchant.find(params[:**merchan**** >>>>>>> t_id]).payments >>>>>>> else >>>>>>> @payments = Payment.all >>>>>>> end >>>>>>> >>>>>>> respond_to do |format| >>>>>>> format.html # index.html.erb >>>>>>> format.json { render json: @merchants } >>>>>>> end >>>>>>> end >>>>>>> >>>>>>> def create >>>>>>> @merchant = Merchant.find(params[:**merchant****_id]) >>>>>>> @payment = @merchant.payments.create(**para****ms[:payment]) >>>>>>> >>>>>>> respond_to do |format| >>>>>>> if @merchant.save >>>>>>> format.html {redirect_to merchants_path} >>>>>>> else >>>>>>> format.html { render action: "new" } >>>>>>> >>>>>>> end >>>>>>> end >>>>>>> >>>>>>> end >>>>>>> >>>>>>> end >>>>>>> >>>>>>> -- >>>>>> You received this message because you are subscribed to the Google >>>>>> Groups "Ruby on Rails: Talk" group. >>>>>> To post to this group, send email to rubyonra...@googlegroups.**com. >>>>>> To unsubscribe from this group, send email to rubyonrails-ta...@** >>>>>> googlegroups**.com. >>>>>> To view this discussion on the web visit https://groups.google.com/d/ >>>>>> **ms**g/rubyonrails-talk/-/**jSZvC8ID4**ycJ<https://groups.google.com/d/msg/rubyonrails-talk/-/jSZvC8ID4ycJ> >>>>>> . >>>>>> >>>>>> For more options, visit https://groups.google.com/**grou**ps/opt_out<https://groups.google.com/groups/opt_out> >>>>>> . >>>>>> >>>>>> >>>>>> >>>>> >>>>> >>>>> >>>>> -- >>>>> ------------------------------****------------------------------****- >>>>> visit my blog at http://jimlabs.heroku.com >>>>> >>>> -- >>>> You received this message because you are subscribed to the Google >>>> Groups "Ruby on Rails: Talk" group. >>>> To post to this group, send email to rubyonra...@googlegroups.**com. >>>> To unsubscribe from this group, send email to rubyonrails-ta...@** >>>> googlegroups.com. >>>> To view this discussion on the web visit https://groups.google.com/d/** >>>> msg/rubyonrails-talk/-/**DbPFCiH_y0UJ<https://groups.google.com/d/msg/rubyonrails-talk/-/DbPFCiH_y0UJ> >>>> . >>>> >>>> For more options, visit https://groups.google.com/**groups/opt_out<https://groups.google.com/groups/opt_out> >>>> . >>>> >>>> >>>> >>> >>> >>> >>> -- >>> ------------------------------**------------------------------**- >>> visit my blog at http://jimlabs.heroku.com >>> >> -- >> You received this message because you are subscribed to the Google Groups >> "Ruby on Rails: Talk" group. >> To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> To unsubscribe from this group, send email to >> rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> To view this discussion on the web visit >> https://groups.google.com/d/msg/rubyonrails-talk/-/I6TAroHPoZkJ. >> >> For more options, visit https://groups.google.com/groups/opt_out. >> >> >> > > > > -- > ------------------------------------------------------------- > visit my blog at http://jimlabs.heroku.com >-- ------------------------------------------------------------- visit my blog at http://jimlabs.heroku.com -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
rubyrookie
2012-Dec-10 08:26 UTC
Re: Re: Values not being being reflected on page after validation error but model has the values
thanks :) On Monday, December 10, 2012 12:18:41 AM UTC-8, jim wrote:> > > > > On Mon, Dec 10, 2012 at 3:45 PM, Jim Ruther Nill <jvn...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org<javascript:> > > wrote: > >> >> >> >> On Mon, Dec 10, 2012 at 3:42 PM, rubyrookie <asaj...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org<javascript:> >> > wrote: >> >>> Thank you very much. I will read up on the difference. Sorry should have >>> bolded my answers. >> >> >> No worries. If you''re looking for the difference, @payment (as you >> already know) uses the same >> record as the one you have in your controllers. If you use >> @merchant.payments.build, you''re >> creating a new payment record which does not contain the values >> submitted by the user :) >> > > regarding your question on the field_error_proc. read this one and please > don''t email users directly :) > > http://guides.rubyonrails.org/configuring.html#configuring-action-view > > >> >> >>> >>> >>> On Sunday, December 9, 2012 11:33:56 PM UTC-8, jim wrote: >>> >>>> >>>> >>>> >>>> On Mon, Dec 10, 2012 at 3:16 PM, rubyrookie <asaj...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >>>> >>>>> >>>>> >>>>> On Sunday, December 9, 2012 11:08:57 PM UTC-8, jim wrote: >>>>> >>>>>> >>>>>> >>>>>> >>>>>> On Mon, Dec 10, 2012 at 2:26 PM, rubyrookie <asaj...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote: >>>>>> >>>>>>> No error . Validation error is populated but form does not retain >>>>>>> values. Payment object has the values though. >>>>>>> >>>>>> >>>>>> This is still confusing. What exactly do you want to do? >>>>>> >>>>>> - Show the validation errors on the form page? -> Yes, it is >>>>>> being displayed >>>>>> - Fix the payment process because you don''t know what validations >>>>>> are failing? No, I know the validations are failing >>>>>> - retain the values passed by the user when validations fail? >>>>>> Yes. The form is not displayed the retained values. I want this to be >>>>>> fixed. >>>>>> >>>>>> >>>> It would''ve helped if you somehow bolded your answers. anyway, you >>>> should be able to do that by >>>> changing this line >>>> >>>> <%= form_for([@merchant, @merchant.payments.build]) do |f| %> >>>> >>>> to >>>> >>>> <%= form_for([@merchant, @payment]) do |f| %> >>>> >>>> Good luck! >>>> >>>> >>>>> >>>>>> >>>>>>> >>>>>>> On Sunday, December 9, 2012 9:53:37 PM UTC-8, rubyrookie wrote: >>>>>>> >>>>>>>> I have a relationship where a merchant can have multiple payments. >>>>>>>> I am posting payments to a merchant and there is a validation error. >>>>>>>> Payment object does have the values retained. Can some one help me fix the >>>>>>>> issue? >>>>>>>> >>>>>>>> View Code-> >>>>>>>> >>>>>>>> <%= @merchant.name %> >>>>>>>> >>>>>>>> <%= form_for([@merchant, @merchant.payments.build]) do |f| %> >>>>>>>> >>>>>>>> <% if @payment.errors.any? %> >>>>>>>> <div id="error_explanation"> >>>>>>>> <h2><%= pluralize(@payment.errors.**coun****t, "error") %> >>>>>>>> prohibited this payment from being saved:</h2> >>>>>>>> >>>>>>>> <ul> >>>>>>>> <% @payment.errors.full_messages.******each do |msg| %> >>>>>>>> <li> >>>>>>>> <%= msg %> >>>>>>>> </li> >>>>>>>> <% end %> >>>>>>>> </ul> >>>>>>>> </div> >>>>>>>> <% end %> >>>>>>>> >>>>>>>> test >>>>>>>> // Prints the values correctly >>>>>>>> <%= @payment.credit_card_number %> >>>>>>>> <%= @payment.zip %> >>>>>>>> <%= @payment.country %> >>>>>>>> >>>>>>>> <div class="field"> >>>>>>>> <%= f.label :credit_card_number %> >>>>>>>> <br /> >>>>>>>> <%= f.text_field :credit_card_number , :autocomplete => "off" %> >>>>>>>> </div> >>>>>>>> <div class="field"> >>>>>>>> <%= f.label :address_line_2 %> >>>>>>>> <br /> >>>>>>>> <%= f.text_field :address_line_2 %> >>>>>>>> </div> >>>>>>>> <div class="field"> >>>>>>>> <%= f.label :city %> >>>>>>>> <br /> >>>>>>>> <%= f.text_field :city %> >>>>>>>> </div> >>>>>>>> <div class="field"> >>>>>>>> <%= f.label :zip %> >>>>>>>> <br /> >>>>>>>> <%= f.text_field :zip %> >>>>>>>> </div> >>>>>>>> <div class="field"> >>>>>>>> <%= f.label :country %> >>>>>>>> <br /> >>>>>>>> <%= f.text_field :country %> >>>>>>>> </div> >>>>>>>> >>>>>>>> <div class="actions"> >>>>>>>> <%= f.submit %> >>>>>>>> </div> >>>>>>>> <% end %> >>>>>>>> >>>>>>>> Controller code-> >>>>>>>> >>>>>>>> class PaymentsController < ApplicationController >>>>>>>> # GET /merchants/1 >>>>>>>> # GET /merchants/1.json >>>>>>>> def new >>>>>>>> @payment = Payment.new >>>>>>>> @merchant = Merchant.find(params[:**merchant****_id]) >>>>>>>> respond_to do |format| >>>>>>>> format.html # show.html.erb >>>>>>>> end >>>>>>>> end >>>>>>>> >>>>>>>> def index >>>>>>>> >>>>>>>> if params[:merchant_id] >>>>>>>> @payments = Merchant.find(params[:**merchan**** >>>>>>>> t_id]).payments >>>>>>>> else >>>>>>>> @payments = Payment.all >>>>>>>> end >>>>>>>> >>>>>>>> respond_to do |format| >>>>>>>> format.html # index.html.erb >>>>>>>> format.json { render json: @merchants } >>>>>>>> end >>>>>>>> end >>>>>>>> >>>>>>>> def create >>>>>>>> @merchant = Merchant.find(params[:**merchant****_id]) >>>>>>>> @payment = @merchant.payments.create(**para****ms[:payment]) >>>>>>>> >>>>>>>> respond_to do |format| >>>>>>>> if @merchant.save >>>>>>>> format.html {redirect_to merchants_path} >>>>>>>> else >>>>>>>> format.html { render action: "new" } >>>>>>>> >>>>>>>> end >>>>>>>> end >>>>>>>> >>>>>>>> end >>>>>>>> >>>>>>>> end >>>>>>>> >>>>>>>> -- >>>>>>> You received this message because you are subscribed to the Google >>>>>>> Groups "Ruby on Rails: Talk" group. >>>>>>> To post to this group, send email to rubyonra...@googlegroups.**com. >>>>>>> To unsubscribe from this group, send email to rubyonrails-ta...@** >>>>>>> googlegroups**.com. >>>>>>> To view this discussion on the web visit >>>>>>> https://groups.google.com/d/**ms**g/rubyonrails-talk/-/**jSZvC8ID4** >>>>>>> ycJ<https://groups.google.com/d/msg/rubyonrails-talk/-/jSZvC8ID4ycJ> >>>>>>> . >>>>>>> >>>>>>> For more options, visit https://groups.google.com/**grou**ps/opt_out<https://groups.google.com/groups/opt_out> >>>>>>> . >>>>>>> >>>>>>> >>>>>>> >>>>>> >>>>>> >>>>>> >>>>>> -- >>>>>> ------------------------------****------------------------------****- >>>>>> visit my blog at http://jimlabs.heroku.com >>>>>> >>>>> -- >>>>> You received this message because you are subscribed to the Google >>>>> Groups "Ruby on Rails: Talk" group. >>>>> To post to this group, send email to rubyonra...@googlegroups.**com. >>>>> To unsubscribe from this group, send email to rubyonrails-ta...@** >>>>> googlegroups.com. >>>>> To view this discussion on the web visit https://groups.google.com/d/* >>>>> *msg/rubyonrails-talk/-/**DbPFCiH_y0UJ<https://groups.google.com/d/msg/rubyonrails-talk/-/DbPFCiH_y0UJ> >>>>> . >>>>> >>>>> For more options, visit https://groups.google.com/**groups/opt_out<https://groups.google.com/groups/opt_out> >>>>> . >>>>> >>>>> >>>>> >>>> >>>> >>>> >>>> -- >>>> ------------------------------**------------------------------**- >>>> visit my blog at http://jimlabs.heroku.com >>>> >>> -- >>> You received this message because you are subscribed to the Google >>> Groups "Ruby on Rails: Talk" group. >>> To post to this group, send email to rubyonra...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<javascript:> >>> . >>> To unsubscribe from this group, send email to >>> rubyonrails-ta...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org <javascript:>. >>> To view this discussion on the web visit >>> https://groups.google.com/d/msg/rubyonrails-talk/-/I6TAroHPoZkJ. >>> >>> For more options, visit https://groups.google.com/groups/opt_out. >>> >>> >>> >> >> >> >> -- >> ------------------------------------------------------------- >> visit my blog at http://jimlabs.heroku.com >> > > > > -- > ------------------------------------------------------------- > visit my blog at http://jimlabs.heroku.com >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/0Cyx0DxVHo8J. For more options, visit https://groups.google.com/groups/opt_out.