Hi, I am beginner to Rails. So far has been a happy PHP developer. I wrote a beginner application in rails. this has been working very good for the web. I want to re-use the model to write views in CLI. How can i do this? I searched on google and could not find a good solution to this one. -- 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 this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 12 September 2011 18:31, maskiran <maskiran-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > I am beginner to Rails. So far has been a happy PHP developer. I wrote > a beginner application in rails. this has been working very good for > the web. I want to re-use the model to write views in CLI.You want to re-use the model to write views in CLI (Command Line Interpreter?)? Sorry, that means nothing to me. Can you explain again what you want to do? 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 this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
say its a basic blog application that has web UI (myblog.com/posts/ new) is an action to add a new post and it shows up a web page with ''title'' and ''content'' field in the GUI that the end user fills in and saves Now I want to do the same thing using a CLI. I login into the server using ssh, then say this on the terminal newpost title content where newpost is my ruby file. It needs to have access to the model of the application so it can save the data into the table. Am I clear here or is it still vague kiran On Sep 12, 2:21 pm, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 12 September 2011 18:31,maskiran<maski...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Hi, > > I am beginner to Rails. So far has been a happy PHP developer. I wrote > > a beginner application in rails. this has been working very good for > > the web. I want to re-use the model to write views in CLI. > > You want to re-use the model to write views in CLI (Command Line > Interpreter?)? Sorry, that means nothing to me. Can you explain > again what you want to do? > > 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
maskiran wrote in post #1021560:> say its a basic blog application that has web UI (myblog.com/posts/ > new) is an action to add a new post and it shows up a web page with > ''title'' and ''content'' field in the GUI that the end user fills in and > saves > > Now I want to do the same thing using a CLI. I login into the server > using ssh, then say this on the terminal > > newpost title content where newpost is my ruby file. It needs to have > access to the model of the application so it can save the data into > the table.You can do that a number of different ways: 1: Using the Rails console interface. $ rails console (or "rails c" for short)> post = Post.create(:title => "My Post", :publish_date => Date.today)2: Use curl to post directly to the web application sending data as JSON $ curl -X POST --data "{\"title\":\"My Post\",\"publish_date\":\"2011-09-12T21:08:57-04:00\"}" http://myblog.com/posts The point is that Rails provides excellent support for making your web application double as a REST web service. You should use Rails controllers as the gateway to all updates to the backing database. Using "rails console" is helpful for testing, or just quickly adding some data to the database. But, any updates to a production application should go through the same controllers that the web application uses for its own updates. -- 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 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 this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 09/12/2011 05:53 PM, maskiran wrote:> say its a basic blog application that has web UI (myblog.com/posts/ > new) is an action to add a new post and it shows up a web page with > ''title'' and ''content'' field in the GUI that the end user fills in and > saves > > Now I want to do the same thing using a CLI. I login into the server > using ssh, then say this on the terminal > > newpost title content where newpost is my ruby file. It needs to have > access to the model of the application so it can save the data into > the table. > > Am I clear here or is it still vague > > kiran > > On Sep 12, 2:21 pm, Colin Law<clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: >> On 12 September 2011 18:31,maskiran<maski...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >>> Hi, >>> I am beginner to Rails. So far has been a happy PHP developer. I wrote >>> a beginner application in rails. this has been working very good for >>> the web. I want to re-use the model to write views in CLI. >> You want to re-use the model to write views in CLI (Command Line >> Interpreter?)? Sorry, that means nothing to me. Can you explain >> again what you want to do? >> >> ColinIf you are intending to do this occasionally as a part of maintenance etc you can use the console (script/console in 2.x and rails console or something like that in ROR 3.x). This will give you access to your objects so you could do something like Post.create(:title =>''something'', ... -- 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 this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hi Thanks a lot. I guess as all of you have suggested my CLI would just be calling the web links directly using curl or wget. I am using such a method now. I thought there might be another way that I could use to write cli, some thing of the form require rails require mydatamodel use the methods in the model, with data from the cli args or a file Thanks Kiran On Sep 12, 10:08 pm, Norm Scherer <normsche...-ihVZJaRskl1bRRN4PJnoQQ@public.gmane.org> wrote:> On 09/12/2011 05:53 PM,maskiranwrote: > > > > > > > > > say its a basic blog application that has web UI (myblog.com/posts/ > > new) is an action to add a new post and it shows up a web page with > > ''title'' and ''content'' field in the GUI that the end user fills in and > > saves > > > Now I want to do the same thing using a CLI. I login into the server > > using ssh, then say this on the terminal > > > newpost title content where newpost is my ruby file. It needs to have > > access to the model of the application so it can save the data into > > the table. > > > Am I clear here or is it still vague > > > kiran > > > On Sep 12, 2:21 pm, Colin Law<clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > >> On 12 September 2011 18:31,maskiran<maski...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > >>> Hi, > >>> I am beginner to Rails. So far has been a happy PHP developer. I wrote > >>> a beginner application in rails. this has been working very good for > >>> the web. I want to re-use the model to write views in CLI. > >> You want to re-use the model to write views in CLI (Command Line > >> Interpreter?)? Sorry, that means nothing to me. Can you explain > >> again what you want to do? > > >> Colin > > If you are intending to do this occasionally as a part of maintenance > etc you can use the console (script/console in 2.x and rails console or > something like that in ROR 3.x). This will give you access to your > objects so you could do something like Post.create(:title =>''something'', ...-- 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.