PullMonkey Blog


28 Feb

Changes/Fixes to the Simple CMS Plugin


You can also view the tutorial. Or you can check out the demo.

We are continuously adding to and changing the Simple CMS Plugin so here is a little rundown of what has been changed so far:

Major Changes:

  • I have updated to rails 2.0.2 so if you are using an older version you will need to change a line in each of the controllers.
  • 1
    2
    3
    4
    5
    6
    
    
    # Where it has:
      self.view_paths << File.join(File.dirname(__FILE__), '..', 'views')
    # Must be Changed to:
      self.template_root = File.join(File.dirname(__FILE__), '..', 'views')
    
    
  • The acts_as_versioned plugin is now required for the revisions. I added this quite some time ago. I did change the rake task to install this plugin as well as the rest.
  • You now have to pass a :prefix if you have one. This is to ensure that all content such as images, media, smiles, etc. work correctly. If your base path is a standard path then you do not need to worry about this.
    For example: I was running 3 rails applications under one domain so it looked like this:

    my.domain.com /blog
    /forum
    /demo

    So I would call my Simple CMS content like this for blog:

  • 1
    2
    3
    
    
    <%= render :simpleCMS => "MyBlog", :admin => true, :prefix => "/blog" %>
    
    
  • Now you can make content viewable and editable from multiple pages by passing :reusable => true. This defaults to false. Your label must be the same in each place you use it. This is very useful for layouts, such as header and footer.
    *NOTE* If you already have content here and you change this variable you will lose all that content as it gives the content a new id and changes the params and how the content is called. For example if I have :reusable set to false and I have content there and I set :reusable to true then it creates content with a different id so I will not be able to use the old content until I change it back to false.

Minor Changes:

  • When you click on a revision you are taken back up to the top of the page instead of having to scroll all the way down a list of 100 revisions, clicking on one, and then manually scrolling all the way back up to the top to see if you even picked the right revision
  • I have added code highlighting and this requires the coderay plugin, which has been added to the rake simple_cms:install_dependencies, and a coderay stylesheet so you need to add that to your application layout. I have included it in the rake simple_cms:install
  • 1
    2
    3
    
    
    <%= stylesheet_link_tag "coderay" %>
    
    
  • I have also changed many things in the javascripts inside the tiny_mce editor so it would be safest just to use the rake tasks that are built in:
  • 1
    2
    3
    4
    
    
    rake simple_cms:uninstall
    rake simple_cms:install
    
    

I have updated the tutorial with all the changes as well.

There is also a demo that you can use to play around with it and ask questions.


19 Feb

Errno::EINVAL – Invalid argument


Windows' servers are pretty much an awful nightmare to get working. A company that I am doing work for had the bright idea of hosting a fairly major web application on windows. Not a good idea, not a good idea at all. This has caused nothing but problems from ferret to having no way of stopping a service to this error - Errno::EINVAL - Invalid argument.
The typical error you get looks something like this:

Errno::EINVAL in .....

Invalid argument
....
.../lib/active_record/base.rb:1358:in `write'
.../lib/active_record/base.rb:1358:in `compute_type'
....

Ya, that is not something you want to get and have no idea what is going on, not to mention that it only happens every once in a while. Especially, when you are already frustrated because nothing else seems to work perfectly.

The error is caused when you are using a windows server and have decided that, as a good windows' administrator, you will create a mongrel service for your application and set it to start automatically. The service knows nothing about STDOUT, so anything written to STDOUT will produce the error above. But, what still baffles me is the complete and utter randomness of the whole situation. Why does it not happen all the time, why only every 6 to 10 times that I hit the same exact page? Well, I can't help you there, but let me know if you have figured it out.

So, if you are lucky enough to get the same error above, then I have a solution for you, well actually a couple solutions. First, if you have the choice, ditch windows, not worth it. However, if you are like me and are forced to use windows for a project then your solution is a simple derivative of what you will find here.
None of those solutions worked for me, or at least not to the point where I was satisfied. They all got me very close, but without a way of still logging STDOUT. The closest and, as the link above points out, the safest was to redirect STDOUT to a logfile:

1
2

STDOUT.reopen(...)

Well, that, unfortunately, did not work for me for some reason, probably some fault of windows, I am sure. If you get it working, stick with that solution. Otherwise, I went with the following:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

###################################
# RAILS_ROOT/lib/std_out_logger
###################################
class StdOutLogger
  def write(s)
    f = File.open("log/stdout.log", "w+")
    f.puts s.inspect
    f.close
  end
end
###################################
# RAILS_ROOT/app/controllers/application.rb
###################################
# redirect the output to a log file for when we run as a service
before_filter {
  $stdout = $stderr = StdOutLogger.new
}

I hope that helps you, it worked for me. Good luck.


5 Responses Filed under: development, Home, rails, ruby Tags:
04 Feb

Open Flash Chart Plugin for Ruby on Rails


Update: Version 2 of Open Flash Chart is available. Examples for version 2 are here.

I just finished converting version 1.9.7 of Open Flash Chart over to ruby, for use with rails.
Check out what I can do now 🙂 I can customize my tooltips:

Extra Tool Tips

View Source Code

More examples can be found on my Open Flash Chart Projects page.
Don't forget to check out the original - http://teethgrinder.co.uk/open-flash-chart/.


02 Feb

Simple CMS Plugin for Rails – with revisions


Well, we have been working on SimpleCMS a little and just for kicks we added revisions.
Check out the Simple CMS Plugin Demo
On this page you will see the "Show all revisions" link at the bottom of the "edit" page.
So feel free to add or delete or change revisions at will.
Also, if you are new to SimpleCMS, check out the sort of rough getting stared page.
Well, enjoy and please leave comments/feedback/requests here in the comments or preferably in the list of requests we have started on the demo page 🙂