I am writing a site with more than one language, is there any easy way or technique to reduct the workload of changing which text to another language.I have an idea, but I don't know whether it is suitable or easy enough. I create a XML that contain all the text in my web, when the user change their language, my program will base on the ...
It seems like there's a lot of cool stuff going on in the Ruby on Rails world. I am primarily a PHP developer, and use Zend Framework for creating web applications, but I would like to learn more about Ruby on Rails.
Where can I find the best online resources for learning Ruby on Rails?
Resources:
Here are some of the resources I've c...
http://stackoverflow.com/questions/1993615/hasmany-build-method-rails
Was my last question. It now works: no errors.
The new problem is that the new unit conversion doesn't associate with an ingredient ID. I thought this was "just supposed to work" from the build method?
Unit Conversion controller:
def new
@ingredient = Ingredient...
following up with this topic:
http://stackoverflow.com/questions/1992094/one-to-many-relationship-in-ror
I am creating a category that may have many products. So, I use the Formtastic as user Chandra Patni suggested. But I find there is a problem when I added attr_accessible to the product.rb.
class Product < ActiveRecord::Base
valid...
Rails is supposed to magically see that a request is a "DELETE" versus "GET" request, right?
I can hit http://localhost/controller/destroy/1 and it'll delete the record. How do developers typically prevent such silly deleting?
...
def post_to_twitter
message = from some where
url = URI.parse('http://twitter.com/statuses/update.xml')
req = Net::HTTP::Post.new(url.path)
req.basic_auth 'account', 'password'
req.set_form_data({'status' => message})
res = Net::HTTP.new(url.host, url.port).start {|http| http.request(req) }
case res
when Net::HTTPSuccess, Net::HTTPRedire...
Hi guy,
I update my rails application 2.0.2 to 2.3.5. I use active scaffold for the administration part.
I change nothing in my code but a problem is coming with the update.
I have a controller 'admin/user_controller' to manage users.
Here is the code of the controller:
class Admin::UserController < ApplicationController
layou...
Users can vote on posts, so I set a many to many relationship in rails:
users have many votes
posts have many votes
posts have many users through votes
users have many posts through votes
Is there a more elegant way to create a new vote than this:
user.votes.create(:post_id => post.id).save
? thanks
...
Hi,
its the first time I post here. I have a problem that i can somehow not solve. Just for the record, I know what instance and class methods are (even if I may not understand them completely ;-)
Here is my model code:
class Car < ActiveRecord::Base
has_many :drives
has_many :users, :through => :drives
def self.user_ids()
ids = []
...
I've been struggling on this rails app for the past week and a half – any help would be appreciated.
Im running from a windows machine [vista]..using: latest rails to date [jan 2. 2010], capistrano 2.5.10, subversive plugin, TortoiseSVN
I've so far:- created the remote repository, created ssh keys, edited the TortoiseSVN config file. N...
I'm trying to get Rails to return a count of the records returned in a search (search results found); I can get Rails to count the total amount of records using
Inventory.count
However when I enter @advsearch.count it blows up. Any ideas? The code below is my controller:
def new
@advsearch = Advsearch.new
end
def creat...
When I upload a photo, my model fails validation, err well even without any validations I'm returned this error:
/tmp/stream20100103-13830-ywmerx-0 is not recognized by the 'identify' command. and
/tmp/stream20100103-13830-ywmerx-0 is not recognized by the 'identify' command.
I'm confident this is not related to ImageMagick becau...
I have a user model in which I have a method for seeing if the user has earned a "badge"
def check_if_badges_earned(user)
if user.recipes.count > 10
award_badge(1)
end
If they have earned a badge, the the award_badge method runs and gives the user the associated badge. Can I do something like this?
def check_if_badges_earned(user...
Given
As the User, I am at a nested new vendors/5/reviews/new. In addition to :params that will get written to the Review model, I need to be able to include tags that belong to the Vendor model.
I have used acts_as_taggable_on (http://github.com/mbleigh/acts-as-taggable-on):
class Vendor....
acts_as_taggable_on :tags, :competito...
I'm building an XML-based webservice in Rails to serve as the backend for an iPhone app, and I'm wondering how I can best achieve an auth scheme that will let me use both GET and POST requests -- i.e. one that doesn't require auth sent in the body of an XML payload.
The wrinkle here is that I'm not using regular HTTP auth. Instead, I'm...
I have been writing specs for controllers and models, but I have never written a helper spec. I have no idea where I start.
I have the following snippet in application_helper.rb
def title(page_title)
content_for(:title) { page_title }
end
How should I write a helper spec on the code?
Also if there's any open-source Rails app...
Im trying to generate n unique random numbers between 1 and max
I tried the following code but doesn't work (returns repeated numbers)
r = [ ]
n.times { v = rand(max) while r.include? v ; r << v}
Whats wrong with it? Thanks
added:
max is thousands
n is 10
...
Hello I've set up a One-to-Many Association between "orders" and "users". I'm wondering how to have console just return an array containing ID's rather than a full array of data:
user = User.find_by_login("Lesa")
user.orders
=> [#, #]
user.orders.id
NoMethodError: undefined method `order' for #<User:0x...
I've noticed that a common error check line in rails is:
if @user.save!
rather than something like
Save
If Save is successful
Blah
Else
Blah
End
So my understanding of "if @user.save!" is that it both saves the object and returns true/false if it was successful. If I call it later on, such as:
@user.save!
if @user.save!
blah
...
Im trying to achieve the following effect in rails:
If the text is bigger than x characters then make it smaller, the next x characters smaller, the next character smaller, ad infinitum
for example x = 7 would output the following html
Lorem i<small>psum do<small>lor sit<small> amet, <small>consecte
<small>tur adip<small>isicing</smal...