Hi
I have the below code in my controller
<% form_for @picture, :picture, :url=>pictures_url, :html => { :multipart => true } do | form | %>
<%=form.file_field :image%>
<%=submit_tag 'Save'%>
<%end%>
which submits to the below controller
class PicturesController < ApplicationController
def create
render :text=>1
end
end
...
I want to remove any leading and trailing non-alphabetic character in my string.
for eg. ":----- pt-br:-" , i want "pt-br"
Thanks
...
hey,
When using accepts_nested_attributes_for, I got stuck when having a validation which required the original to be present. The code will help clear up that sentence.
class Foo < ActiveRecord::Base
has_one :bar
accepts_nested_attributes :bar
end
class Bar < ActiveRecord::Base
#property name: string
belongs_to :foo
valida...
I'd like to have one yaml object refer to another, like so:
intro: "Hello, dear user."
registration: $intro Thanks for registering!
new_message: $intro You have a new message!
The above syntax is just an example of how it might work (it's also how it seems to work in this cpan module.)
I'm using the standard ruby yaml parser.
Is t...
It seems like LDAP requires strings with non-ASCII characters to be Base64 encoded. The way to tell it that a string is to be parsed as a base64 encoded string is to add an extra colon to the attribute name such that "cn: name" becomes "cn:: name" (according to this site).
Now, my question is: How do I tell Ruby LDAP to do this? I could...
I need to bring an array of ruby objects in JSON. I will need to find the item in the JSON object by id, so I think it is best that the id is the key of each object. This structure makes the most sense to me:
{
"1": {"attr1": "val1", "attr2": "val2"},
"2": {"attr1": "val1", "attr2": "val2"},
"3": {"attr1": "val1", "a...
Hello,
I've been searching for a while, and I can't find any modern rails plugin management tools. I found several gem management tools (such as bundler and isolate), but no plugin management tools. The closest thing to that I found was piston, and that's not exactly what I was looking for was it was for plugin svn:externals managemen...
How do I choose a particular a method call in the inheritance chain?
class A
def boo; puts "A:Boo"; end
end
class B < A
def boo; super; puts "B:Boo"; end
end
class C < B
def boo; self.A.boo(???); puts "C:Boo"; end
end
Thus the output would be A:Boo, C:Boo
TIA,
-daniel
...
Background:
I grew up on using Perl/Python/Ruby for sysadmin-type tasks and shell scripting. I always avoided Bash scripting whenever I needed anything programmer-ish, like functions, looping or control structures. Back then, I could pick my favorite tool for whatever the job.
Problem:
Now I am working in a situation where the preferr...
This question is about formatting ruby's strings.
In Python, built-in data structures have a built-in to-string method, and so when a variable is printed, the string is conveniently formatted to be reflective of the data structure used. For example:
>>>$ python
Python 2.6.4 (r264:75706, Dec 7 2009, 18:45:15)
[GCC 4.4.1] on linux2
Type...
HAML:
= link_to 'redeem', redeem_admin_organization_path(organization), :class => 'button_short live redeem'
Controller:
def redeem
@organization = Organization.find(params[:id])
@organization.update_attribute('accumulated_credits', '0')
end
redeem.js.haml:
== $("#organization_#{@organization.id} .redeem").html("#{escape_javas...
I am working through a tutorial with the following code:
<h3>New Comment</h3>
<%= render :partial => @comment = Comment.new,
:locals => { :button_name => "Create" } %>
I believe that 'render :partial => @comment' works like 'render :partial => "comment", :object => @comment'
Where does ' = Comment.new' fit in?
Is it shorthand f...
I am not clear yet on the proper way to run raw sql queries with sequel
currently I am trying this but not sure if it is the correct way
DB.fetch("SELECT * FROM zone WHERE dialcode = '#{@dialcode}' LIMIT 1") do |row|
@zonename = row
end
What would be good is if I can run the queries as raw then access the results like normal
e.g
i...
When adding a key to an existing model (with existing data) via MongoMapper, I can create new documents with the new key but when trying to access existing documents using that same key it fails stating that it's an "undefined method."
I was wondering if anyone had any insight.
Thanks in advance!
(Yes, these examples are truncated.)
...
How do I take a numeric month, day and year from three separate text inputs and parse a proper value for my DateTime field in the db?
...
I have an array(list?) in ruby:
allRows = ["start","one","two","start","three","four","start","five","six","seven","eight","start","nine","ten"]
I need to run a loop on this to get a list that clubs elements from "start" till another "start" is encountered, like the following:
listOfRows = [["start","one","two"],["start","three","fou...
I have an array of Elements, and each element has a property :image.
I would like an array of :images, so whats the quickest and least expensive way to achieve this. Is it just iteration over the array and push each element into a new array, something like this:
images = []
elements.each {|element| images << element.image}
...
Hello,
My objective is to convert form input, like "100 megabytes" or "1 gigabyte", and converts it to a filesize in kilobytes I can store in the database. Currently, I have this:
def quota_convert
@regex = /([0-9]+) (.*)s/
@sizes = %w{kilobyte megabyte gigabyte}
m = self.quota.match(@regex)
if @sizes.include? m[2]
eval("se...
I have done the front-end of my design, but I have no experience in web programming. Would like to pick up a language asap so that I can deploy the product. Which is faster to pick up between the two? I know there is always debate in which is better. I think either one serves well for me, but I want to know which one is easier to learn, ...
I have a polymorphic association that looks like this:
class Line < ActiveRecord::Base
belongs_to :item, :polymorphic => true
end
class Education < ActiveRecord::base
has_many :lines, :as => :item
end
class Work < ActiveRecord::base
has_mayn :lines, :as => :item
end
I'd like a simple way to create a new Line from the parent...