Hey, I''m trying to do the following below: if @logos == nil @image Magick::ImageList.new("/home/rajeev/Desktop/logo/logo/public/logos/0000/0001/28.jpg") @image = @image.write("/home/rajeev/Desktop/test.jpg") @logos = Magick::ImageList.new("/home/rajeev/Desktop/test.jpg") @logos = @logos.rotate(90) @logos = @logos.write("/home/rajeev/Desktop/test.jpg") else @logos = Magick::ImageList.new("/home/rajeev/Desktop/test.jpg") @logos = @logos.rotate(90) @logos = @logos.write("/home/rajeev/Desktop/test.jpg") end I''m getting an image then creating a copy of it on the desktop. This is then rotated and saved in the same location. So for the else statement i want to say if the image is already on the desktop location then i just want to rotate it again. Hope this makes sense, but the if..else block doesn''t seem to work. Would appreciate any help. Cheers -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Rajeev Kala wrote:> Hey, > > I''m trying to do the following below: > > if @logos == nil > @image > Magick::ImageList.new("/home/rajeev/Desktop/logo/logo/public/logos/0000/0001/28.jpg") > @image = @image.write("/home/rajeev/Desktop/test.jpg") > @logos = Magick::ImageList.new("/home/rajeev/Desktop/test.jpg") > @logos = @logos.rotate(90) > @logos = @logos.write("/home/rajeev/Desktop/test.jpg") > > else > @logos = Magick::ImageList.new("/home/rajeev/Desktop/test.jpg") > @logos = @logos.rotate(90) > @logos = @logos.write("/home/rajeev/Desktop/test.jpg") > end > > I''m getting an image then creating a copy of it on the desktop. This is > then rotated and saved in the same location. So for the else statement i > want to say if the image is already on the desktop location then i just > want to rotate it again. Hope this makes sense, but the if..else block > doesn''t seem to work. > > Would appreciate any help. > > CheersHi Rajeev I hope this will help If you want to write if else statement in Rails it should be like this If statement block elsif statement block else statement block end Note : It is "elsif" not elseif Hope this will help Abhimanyu -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On first glance, it looks like your ''else'' block won''t ever run unless there is some definition of @logos above that code that you had forgotten to paste. This may be why the second rotation doesn''t ever happen (if that is your problem). Forgive me if I''m misinterpreting you. - Edd http://www.eddm.co.uk On 10/25/07, Abhi Manyu <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Rajeev Kala wrote: > > Hey, > > > > I''m trying to do the following below: > > > > if @logos == nil > > @image > > Magick::ImageList.new("/home/rajeev/Desktop/logo/logo/public/logos/0000/0001/28.jpg") > > @image = @image.write("/home/rajeev/Desktop/test.jpg") > > @logos = Magick::ImageList.new("/home/rajeev/Desktop/test.jpg") > > @logos = @logos.rotate(90) > > @logos = @logos.write("/home/rajeev/Desktop/test.jpg") > > > > else > > @logos = Magick::ImageList.new("/home/rajeev/Desktop/test.jpg") > > @logos = @logos.rotate(90) > > @logos = @logos.write("/home/rajeev/Desktop/test.jpg") > > end > > > > I''m getting an image then creating a copy of it on the desktop. This is > > then rotated and saved in the same location. So for the else statement i > > want to say if the image is already on the desktop location then i just > > want to rotate it again. Hope this makes sense, but the if..else block > > doesn''t seem to work. > > > > Would appreciate any help. > > > > Cheers > > > Hi Rajeev > > I hope this will help If you want to write if else statement in Rails it > should be like this > > > If > statement block > elsif > statement block > else > statement block > end > > > Note : It is "elsif" not elseif > > > Hope this will help > > Abhimanyu > > > > > > > -- > Posted via http://www.ruby-forum.com/. > > > >-- Edd Morgan thewzpr-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org +44 (0) 7979 474 043 --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
That''s what I''m trying to do, but shouldn''t the else block execute if the if statement is false? Cheers -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi -- On Thu, 25 Oct 2007, Rajeev Kala wrote:> > That''s what I''m trying to do, but shouldn''t the else block execute if > the if statement is false?Yes, and it will. I can promise you that if/else/end works :-) Where do you set @logos? David -- Upcoming training by David A. Black/Ruby Power and Light, LLC: * Advancing With Rails, Edison, NJ, November 6-9 * Advancing With Rails, Berlin, Germany, November 19-22 * Intro to Rails, London, UK, December 3-6 (by Skills Matter) See http://www.rubypal.com for details! --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
That is correct, and syntactically I see nothing wrong with your code. However, from what I can see the if statement will always evaluate to true because @logos will always be null. - Edd On 10/25/07, Rajeev Kala <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > That''s what I''m trying to do, but shouldn''t the else block execute if > the if statement is false? > > Cheers > -- > Posted via http://www.ruby-forum.com/. > > > >-- Edd Morgan thewzpr-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org +44 (0) 7979 474 043 --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I''m still a bit confused with this even though it seems simple. If the if block gets executed the first time that means @logos has a value right? Which means the second time round the if statement will be false hence execute the else block. That''s what I understand anyways. Basically what I want to say is if an image called test.jpg is already present on the desktop location (/home/rajeev/Desktop/test.jpg) then execute the else block (rotate the image again). Sorry if I''m being to long I''m still new to this :-) Cheers -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 25 Oct 2007, at 14:42, Rajeev Kala wrote:> > I''m still a bit confused with this even though it seems simple. If the > if block gets executed the first time that means @logos has a value > right? Which means the second time round the if statement will be > false > hence execute the else block. That''s what I understand anyways. >Only if it''s the same object, since @logos is just an instance variable. If for example this was in a controller then the second time you hit the web page you''ll get a new instance of the controller and so @logos will be nil again. Fred --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hey, I''m trying to execute the code below which i have tested and works fine: <--text.rb--> p = 2 if p == 1 pos = NorthGravity elsif p == 2 pos = SouthGravity else end clown = Magick::ImageList.new("3.jpeg") text = Magick::Draw.new text.annotate(clown, 0, 0, 0, 0, "Text") { self.font_family = ''Helvetica'' self.font_style = Magick::ItalicStyle self.gravity = pos self.pointsize = 20 self.stroke = ''transparent'' self.fill = ''#0000A9'' self.font_weight = Magick::BolderWeight } clown.write(''text.jpg'') However when I try to do almost the same in my rails application I get an error: TypeError in MainController#addtext wrong enumeration type - expected Magick::GravityType, got NilClass Below is the code: <--main_controller.rb--> def addtext @logo = Logo.find(params[:id]) t = params[:text] c = params[:colour] s = params[:size].to_f p = params[:position] if p == 1 pos = NorthGravity elsif p == 2 pos = SouthGravity else end @image = File.join(RAILS_ROOT, "public/images/logo.jpg") @image = Magick::ImageList.new(@image) @image = @image.first text = Magick::Draw.new text.annotate(@image, 0, 0, 0, 0, t){ self.font_family = ''Helvetica'' self.font_style = Magick::ItalicStyle self.gravity = pos self.pointsize = s self.stroke = ''transparent'' self.fill = c self.font_weight = Magick::BolderWeight } @image = @image.write(File.join(RAILS_ROOT, "public/images/logo.jpg")) {self.quality = 100} render :action => "edit" end p will be either 1 or 2 depending on the value of params[:position] from the form. <select name="position"> <option value="">Select a position</option> <option value="">----------------------</option> <option value="1">North</option> <option value="2">South</option> Any help?? Cheers -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Perhaps check to see if your version of ImageMagick matches your rmagick gem. I had this problem a few days ago, updating to a newer ImageMagick solved the problem. There is also another fix, where it says it got the wrong type (it''ll be in an rmagick file, I have it as a plugin under my rails directory), open the file at that line and at the end of the statement (it will be a function followed by several params), remove the last param (it''s a true from memory). I''m doing all this from memory, so sorry if it doesn''t match up, but that also solved the problem for me (and took me quite a while to find :(). Good luck, James On Nov 6, 2007 9:55 PM, Rajeev Kala <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Hey, > > I''m trying to execute the code below which i have tested and works fine: > > <--text.rb--> > > p = 2 > > if p == 1 > pos = NorthGravity > elsif p == 2 > pos = SouthGravity > else > end > > clown = Magick::ImageList.new("3.jpeg") > text = Magick::Draw.new > text.annotate(clown, 0, 0, 0, 0, "Text") { > self.font_family = ''Helvetica'' > self.font_style = Magick::ItalicStyle > self.gravity = pos > self.pointsize = 20 > self.stroke = ''transparent'' > self.fill = ''#0000A9'' > self.font_weight = Magick::BolderWeight > } > clown.write(''text.jpg'') > > However when I try to do almost the same in my rails application I get > an error: > > TypeError in MainController#addtext > > wrong enumeration type - expected Magick::GravityType, got NilClass > > Below is the code: > > <--main_controller.rb--> > > def addtext > @logo = Logo.find(params[:id]) > t = params[:text] > c = params[:colour] > s = params[:size].to_f > p = params[:position] > > if p == 1 > pos = NorthGravity > elsif p == 2 > pos = SouthGravity > else > end > > > @image = File.join(RAILS_ROOT, "public/images/logo.jpg") > @image = Magick::ImageList.new(@image) > @image = @image.first > > text = Magick::Draw.new > > text.annotate(@image, 0, 0, 0, 0, t){ > self.font_family = ''Helvetica'' > self.font_style = Magick::ItalicStyle > self.gravity = pos > self.pointsize = s > self.stroke = ''transparent'' > self.fill = c > self.font_weight = Magick::BolderWeight > } > @image = @image.write(File.join(RAILS_ROOT, "public/images/logo.jpg")) > {self.quality = 100} > > render :action => "edit" > > end > > p will be either 1 or 2 depending on the value of params[:position] from > the form. > > <select name="position"> > <option value="">Select a position</option> > <option value="">----------------------</option> > > <option value="1">North</option> > > <option value="2">South</option> > > Any help?? > > Cheers > -- > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> > p will be either 1 or 2 depending on the value of params[:position] > from > the form. >actually params[:position] will be the string ''1'' or the string ''2'', however you''re comparing it to integers, hence you fall through to the else statement. fred --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hey, These are the versions: irb(main):012:0> puts Magick::Long_version This is RMagick 1.15.10 ($Date: 2007/06/09 16:45:25 $) Copyright (C) 2007 by Timothy P. Hunter Built with ImageMagick 6.3.6 10/15/07 Q16 http://www.imagemagick.org Built for ruby 1.8.5 (2006-08-25) [i486-linux] Web page: http://rmagick.rubyforge.org Email: rmagick-GrnCvJ7WPxnNLxjTenLetw@public.gmane.org How do I locate the rmagick file you mentioned, because I don''t have it as a plugin under my rails directory? Cheers James Brooks wrote:> Perhaps check to see if your version of ImageMagick matches your rmagick > gem. I had this problem a few days ago, updating to a newer ImageMagick > solved the problem. There is also another fix, where it says it got the > wrong type (it''ll be in an rmagick file, I have it as a plugin under my > rails directory), open the file at that line and at the end of the > statement > (it will be a function followed by several params), remove the last > param > (it''s a true from memory). > > I''m doing all this from memory, so sorry if it doesn''t match up, but > that > also solved the problem for me (and took me quite a while to find :(). > > Good luck, > James > > On Nov 6, 2007 9:55 PM, Rajeev Kala <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>-- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks Fred, That worked. Stupid mistake by me really just have to convert to integer. Cheers Frederick Cheung wrote:>> >> p will be either 1 or 2 depending on the value of params[:position] >> from >> the form. >> > actually params[:position] will be the string ''1'' or the string ''2'', > however you''re comparing it to integers, hence you fall through to the > else statement. > > 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 post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---