Hi all i am following this like for basic paypal http://railscasts.com/episodes/141-paypal-basics and i got this error View: <%= link_to "Checkout", @cart.paypal_url() %> undefined method `paypal_url'' for nil:NilClass despite i have this code in my model called Card Cart Model: class Cart < ActiveRecord::Base def paypal_url(return_url) values = { :business => '''', :cmd => ''_cart'', :upload => 1, :return => return_url, :invoice => id } line_items.each_with_index do |item, index| values.merge!({ "amount_#{index+1}" => 500, "item_name_#{index+1}" => car, "item_number_#{index+1}" => 5, "quantity_#{index+1}" => 1 }) end "https://www.sandbox.paypal.com/cgi-bin/webscr?" + values.to_query end end it is unable to identify it what is the problem Cheers -- 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/-/ph2CGAAof2cJ. For more options, visit https://groups.google.com/groups/opt_out.
Putting aside the fact that you didn''t give enough information about to diagnose the problem, I''ll only answer because it''s obvious. The answer to your question lies in the origins of the @cart instance variable. It''s not defined automagically; you should define it in the controller, and you are most likely forgetting to do it. On Sat, Sep 1, 2012 at 12:43 AM, Khan <emailtosameenakhan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi all i am following this like for basic paypal > http://railscasts.com/episodes/141-paypal-basics > and i got this error > > > View: > > <%= link_to "Checkout", @cart.paypal_url() %> > > undefined method `paypal_url'' for nil:NilClass > despite i have this code in my model called Card > > Cart Model: > > class Cart < ActiveRecord::Base > > > > > > def paypal_url(return_url) > values = { > :business => '''', > :cmd => ''_cart'', > :upload => 1, > :return => return_url, > :invoice => id > } > line_items.each_with_index do |item, index| > values.merge!({ > "amount_#{index+1}" => 500, > "item_name_#{index+1}" => car, > "item_number_#{index+1}" => 5, > "quantity_#{index+1}" => 1 > }) > end > "https://www.sandbox.paypal.com/cgi-bin/webscr?" + values.to_query > end > > > end > > it is unable to identify it > > what is the problem > > > Cheers > > > > -- > 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/-/ph2CGAAof2cJ. > For more options, visit https://groups.google.com/groups/opt_out. > > >-- 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.
Hey, you got to set @cart in your controller. That''s what the error is saying: nil.paypal_url. 2012/9/1 Khan <emailtosameenakhan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>> Hi all i am following this like for basic paypal > http://railscasts.com/episodes/141-paypal-basics > and i got this error > > > View: > > <%= link_to "Checkout", @cart.paypal_url() %> > > undefined method `paypal_url'' for nil:NilClass > despite i have this code in my model called Card > > Cart Model: > > class Cart < ActiveRecord::Base > > > > > > def paypal_url(return_url) > values = { > :business => '''', > :cmd => ''_cart'', > :upload => 1, > :return => return_url, > :invoice => id > } > line_items.each_with_index do |item, index| > values.merge!({ > "amount_#{index+1}" => 500, > "item_name_#{index+1}" => car, > "item_number_#{index+1}" => 5, > "quantity_#{index+1}" => 1 > }) > end > "https://www.sandbox.paypal.com/cgi-bin/webscr?" + values.to_query > end > > > end > > it is unable to identify it > > what is the problem > > > Cheers > > > > -- > 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/-/ph2CGAAof2cJ. > For more options, visit https://groups.google.com/groups/opt_out. > > >-- 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.
On 1 September 2012 06:43, Khan <emailtosameenakhan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi all i am following this like for basic paypal > http://railscasts.com/episodes/141-paypal-basics > and i got this error > > > View: > > <%= link_to "Checkout", @cart.paypal_url() %> > > undefined method `paypal_url'' for nil:NilClassThat means that @cart is nil. The error messages in rails are not always perfectly clear but usually careful consideration of the message will yield clues as to the problem.> despite i have this code in my model called Card > > Cart Model: > > class Cart < ActiveRecord::Base >[snip]> end > > > end > > it is unable to identify it > > what is the problemAs I said at the top the problem is that @cart is nil, it is probably not a problem in the model itself, but in the controller. Have a look at the Rails Guide on debugging which will provide techniques you can use to debug the code and work out why it is nil. Colin -- 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.
Thanks for your response On Sat, Sep 1, 2012 at 11:17 AM, Marcelo de Moraes Serpa < celoserpa-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Putting aside the fact that you didn''t give enough information about to > diagnose the problem, I''ll only answer because it''s obvious. > > The answer to your question lies in the origins of the @cart instance > variable. It''s not defined automagically; you should define it in the > controller, and you are most likely forgetting to do it. > > > On Sat, Sep 1, 2012 at 12:43 AM, Khan <emailtosameenakhan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote: > >> Hi all i am following this like for basic paypal >> http://railscasts.com/episodes/141-paypal-basics >> and i got this error >> >> >> View: >> >> <%= link_to "Checkout", @cart.paypal_url() %> >> >> undefined method `paypal_url'' for nil:NilClass >> despite i have this code in my model called Card >> >> Cart Model: >> >> class Cart < ActiveRecord::Base >> >> >> >> >> >> >> def paypal_url(return_url) >> values = { >> :business => '''', >> :cmd => ''_cart'', >> :upload => 1, >> :return => return_url, >> :invoice => id >> >> } >> line_items.each_with_index do |item, index| >> values.merge!({ >> "amount_#{index+1}" => 500, >> "item_name_#{index+1}" => car, >> "item_number_#{index+1}" => 5, >> >> "quantity_#{index+1}" => 1 >> }) >> end >> "https://www.sandbox.paypal.com/cgi-bin/webscr?" + values.to_query >> >> end >> >> >> end >> >> it is unable to identify it >> >> what is the problem >> >> >> Cheers >> >> >> >> -- >> 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/-/ph2CGAAof2cJ. >> For more options, visit https://groups.google.com/groups/opt_out. >> >> >> > > -- > 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. > > >-- 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.