With> rails console --sandboxI cant test my models, save data to db and all will be rolled back after. But is it possible to test view helpers from console? I talk about these helpers:> post_path > link_to > url_for > edit_post_path > new_post_pathWhen I call them, I get an error: irb(main):003:0> post_path(:post) NameError: undefined local variable or method `post_path'' for main:Object Is there a way to call those methods from Rails console? Through which object do I need to call them? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/7184cd47c4759192a252fc923e70d66e%40ruby-forum.com?hl=en-US. For more options, visit https://groups.google.com/groups/opt_out.
tamouse mailing lists
2013-May-29 22:33 UTC
Re: How to run view helpers from rails console?
Test them from tests. On Wed, May 29, 2013 at 4:25 PM, Wins Lin <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> With >> rails console --sandbox > I cant test my models, save data to db and all will be rolled back > after. > > But is it possible to test view helpers from console? I talk about these > helpers: >> post_path >> link_to >> url_for >> edit_post_path >> new_post_path > > When I call them, I get an error: > irb(main):003:0> post_path(:post) > NameError: undefined local variable or method `post_path'' for > main:Object > > Is there a way to call those methods from Rails console? Through which > object do I need to call them? > > -- > Posted via http://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/7184cd47c4759192a252fc923e70d66e%40ruby-forum.com?hl=en-US. > 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 unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAHUC_t8wWOA52t7cu-%3DVGK_UipTXoCkzG_kRSaEiOY49XnPNRA%40mail.gmail.com?hl=en-US. For more options, visit https://groups.google.com/groups/opt_out.
On Wednesday, May 29, 2013 10:25:59 PM UTC+1, Ruby-Forum.com User wrote:> > With > > rails console --sandbox > I cant test my models, save data to db and all will be rolled back > after. > > But is it possible to test view helpers from console? I talk about these > helpers: > > post_path > > link_to > > url_for > > edit_post_path > > new_post_path > > When I call them, I get an error: > irb(main):003:0> post_path(:post) > NameError: undefined local variable or method `post_path'' for > main:Object > > Is there a way to call those methods from Rails console? Through which > object do I need to call them? > >The routing helpers are all defined on Rails.application.routes.url_helpers The other helpers are defined on the helper object helper.number_with_precision(1.1235) This doesn''t always work - some of the helpers rely on their being a controller/request around and these won''t be able to run. Fred> -- > Posted via http://www.ruby-forum.com/. >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/9604e641-9fe4-4e34-b746-14b781e3a6c9%40googlegroups.com?hl=en-US. For more options, visit https://groups.google.com/groups/opt_out.
i think you can also use app for the url_helpers app.posts_path for example On Thu, May 30, 2013 at 2:21 PM, Frederick Cheung < frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > On Wednesday, May 29, 2013 10:25:59 PM UTC+1, Ruby-Forum.com User wrote: >> >> With >> > rails console --sandbox >> I cant test my models, save data to db and all will be rolled back >> after. >> >> But is it possible to test view helpers from console? I talk about these >> helpers: >> > post_path >> > link_to >> > url_for >> > edit_post_path >> > new_post_path >> >> When I call them, I get an error: >> irb(main):003:0> post_path(:post) >> NameError: undefined local variable or method `post_path'' for >> main:Object >> >> Is there a way to call those methods from Rails console? Through which >> object do I need to call them? >> >> > The routing helpers are all defined on Rails.application.routes.url_helpers > > The other helpers are defined on the helper object > > helper.number_with_precision(1.1235) > > This doesn''t always work - some of the helpers rely on their being a > controller/request around and these won''t be able to run. > > Fred > > >> -- >> Posted via http://www.ruby-forum.com/. >> > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To view this discussion on the web visit > https://groups.google.com/d/msgid/rubyonrails-talk/9604e641-9fe4-4e34-b746-14b781e3a6c9%40googlegroups.com?hl=en-US > . > > 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 unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAJ8y7Ve6gmXpcnonwFn26KeVXqrScBTEm-FOKaZa53aGrHun2A%40mail.gmail.com?hl=en-US. For more options, visit https://groups.google.com/groups/opt_out.
Jim ruther Nill wrote in post #1110649:> i think you can also use app for the url_helpers > > app.posts_path for exampleOh, yes, this works, they both work. Thank you, that''s what I was looking for. irb(main):005:0> app.posts_path => "/posts" irb(main):006:0> Rails.application.routes.url_helpers => #<Module:0x2d854b8> irb(main):007:0> Rails.application.routes.url_helpers.posts_path => "/posts" -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/936dde3274442e37251c9381a027fd8c%40ruby-forum.com?hl=en-US. For more options, visit https://groups.google.com/groups/opt_out.