Hi!
Is it good when url to show and destroy are same? How it can be changed in RoR if i want continue use standard tools like script/generate scaffold ?
Thanks.
hi guys! can you help me with these codes: http://pastie.org/908345, its two sortable lists and I need to get the serialize parameter of those lists to be passed when I click the submit button but I always get "(an empty string)" on "console.log". I'm using jquery-ui for this functionality. thanks!
Hi,
i've added code
config.gem "authlogic-oauth", :lib => "authlogic_oauth"
to the environment.rb file in my app and got error
undefined method 'add_acts_as_authentic_module' for ActiveRecord::Base::Class
is there any solution to solve it?
Hi all,
How do I get line numbers to be reported with my errors when testing. Here is what I get back on a typical error:
josh@josh-laptop:~/d/test$ ruby unit/line_test.rb -n test_update
Loaded suite unit/line_test
Started
E
Finished in 0.066663 seconds.
1) Error:
test_update(LineTest):
NameError: undefined local variable or method `sdf' for
#<LineTest:0xb6e61304>
1 tests, 0 assertions, 0 failures, 1 errors
It is tough to debug without a line number and filename. From the code
samples I've seen, people generally get back a more verbose error
reports. How do I enable this?
Thanks!
Here is the example from the crack documentation:
json = '{"posts":[{"title":"Foobar"}, {"title":"Another"}]}'
Crack::JSON.parse(json)
=> {"posts"=>[{"title"=>"Foobar"}, {"title"=>"Another"}]}
But how do I actually access the data in the hash?
I've tried the following:
array = Crack::JSON.parse(json)
array["posts"]
array["posts"] shows all the values, but I tried array["posts"]["title"] and it didn't work.
Here is what I am trying to parse as an example:
{"companies"=>[{"city"=>"San Mateo", "name"=>"Jigsaw", "address"=>"777 Mariners Island Blvd Ste 400", "zip"=>"94404-5059", "country"=>"USA", "companyId"=>4427170, "activeContacts"=>168, "graveyarded"=>false, "state"=>"CA"}], "totalHits"=>1}
I want to access the individual elements under companies....like city and name.
Paperclip produces this error, after checking out the plugin's rails3 branch.
My Gemfile has following line:
gem 'paperclip', :git => 'http://github.com/thoughtbot/paperclip.git', :branch => 'rails3'
And the error message is:
NoMethodError: undefined method `has_attached_file' for #<Class:0x2a50530>
I have two models -- User and Entry -- that are related through a has_many relationship (a User has many Entries). I'm using RESTful routing, and have the following in my routes.rb file:
map.resource :user, :controller => "users" do |user|
user.resources :entries
end
This seems to work, but in my partial _form file, when I do this:
form_for [@current_user, @entry] do |f|
# Form stuff
end
It generates a URL like this:
/user/entries.%23%3Cuser:0xb6a6aea8%3E
instead of
/user/entries
Am I missing something?
I should note that the correct classes are applied to the form when doing creation vs. editing, so it does seem to be correctly interpreting what I'm trying to do -- it's just that I can't submit the form to an invalid url.
How can I possibly turn into named_scope?
def self.hero_badge_awardees
return User.find_by_sql("select users.*, awards.*, badges.badge_type
from users, awards, badges
where awards.user_id = users.id and badges.id = awards.badge_id and badges.badge_type = 'HeroBadge'")
end
I'm using Ym4r and want to add a polyline to my map.
This works:
polyline = GPolyline.new([[27.4037755983,89.4263076782],[27.5155793659,89.3245124817]],"#ff0000",3,1.0)
@map.record_init @map.add_overlay(polyline)
But this doesn't:
polystring = "[27.4037755983,89.4263076782],[27.5155793659,89.3245124817]"
polyline = GPolyline.new([polystring],"#ff0000",3,1.0)
@map.record_init @map.add_overlay(polyline)
Any idea why?
Regards
Arwed
I keep getting the following error when installing Ruby 1.9.3-p125:
It seems your ruby installation is missing psych (for YAML output). To
eliminate this warning, please install libyaml and reinstall your
ruby.
I've tried installing LibYAML and for some reason it's installing in my home directory on OS X Lion where the Documents, Music, Pictures, etc. folders are.
Any idea how I can get rid of this error, properly install YAML and never have to deal with this again?
I'm pulling data from Harvest. Here are my two models and schema:
# schema
create_table "clients", :force => true do |t|
t.string "name"
t.integer "harvest_id"
end
create_table "projects", :force => true do |t|
t.string "name"
t.integer "client_id"
t.integer "harvest_id"
end
# Client.rb
has_many :projects, :foreign_key => 'client_id' # not needed, I know
# Project.rb
belongs_to :client, :foreign_key => 'harvest_id'
I'm trying to get the Projects to find their client by matching Project.client_id to a Client.harvest_id. Here is what I'm getting instead.
> Project.first.client_id
=> 187259
Project.first.client
=> nil
Client.find(187259).projects
=> []
Is this possible? Thanks!
Hi, i'm deploying a ror application and now i have to rewrite the url (in apache) to
add a prefix www to the url
add / to the end of the url
So i took the following approach:
RewriteCond %{REQUEST_URI} ^/[^\.]+[^/]$
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1/ [R=301,L]
RewriteCond %{HTTP_HOST} ^foo\.com
RewriteRule ^(.*)$ http://www.foo.com/$1 [R=301,L]
The problem is that it is appending two trailing slash to my url
So for example a resource /question/ask are becoming:
http://foo.com//question/ask
I tried to add the following Rule before all my Rewrite rules to try to remove the double //:
RewriteCond %{REQUEST_URI} ^//
RewriteRule ([^/]*)/+(.*) http://www.foo.com/$1/$2 [R=301,L]
but it didnt work.. any idea to rip off all extras "//" added to the url?
my controller uses code like this:
if params[:commit] == "Submit"
this used to work fine when I just had buttons. however, now I am using images as buttons like below:
<%= image_submit_tag 'butons/Add-08.png', :class => 'image-button-submit' %>
How can I pass the commit variable with value Submit along with this image_submit_tag?
I am using STI and am wondering, do I have to have a separate controller for each model? I have a situation where I only use the create and edit actions for one model in the STI relationship, but I get an 'undefined method' error if I try to do a form for. More specifically, I have two models that inherit from List:
class RegularList < List
class OtherList < List
and I have a lists controller that handles these actions, but I only create new models with RegularList using forms. i.e. the only situation where I use a form_for to create a new List object is with RegularList. What I would like to do is something like:
class ListsController < ApplicationController
def new
@list = RegularList.new
end
otherwise the route for creating a new list looks like regular_list/new but I would like it to just be list/new. Thoughts?
hi
i have created a LocalizedString custom data type for storing / displaying translations using mongo_mapper.
This works for one field but as soon as i introduce another field they get written over each and display only one value for both fields. The to_mongo and from_mongo seem to be not workings properly. Please can any one help with this ? her is the code :
class LocalizedString
attr_accessor :translations
def self.from_mongo(value)
puts self.inspect
@translations ||= if value.is_a?(Hash)
value
elsif value.nil?
{}
else
{ I18n.locale.to_s => value }
end
@translations[I18n.locale.to_s]
end
def self.to_mongo(value)
puts self.inspect
if value.is_a?(Hash)
@translations = value
else
@translations[I18n.locale.to_s] = value
end
@translations
end
end
Thank alot
Rick
I am trying to create a model in ruby that uses a BIGINT datatype (as opposed to the INT done by :integer).
I have search all over Google, but all I seem to find is "run an SQL statement to alter the table to a BIGINT" - This seems a bit hack-ish to me, so I wanted to know if there was a way to specify a bigint in the ruby system like :big_int or something
Any ideas?
Hi,
I'd like to allow users the option to register using their Twitter account. Basically, I'll present them with a standard signup form (name, login, email, pwd, pwd_confirm) as well as a "Signup with Twitter" link.
If a user chooses to signup with Twitter creds, then I'll create a user record in db. Then I'd like to be able to allow a user to authenticate using their Twitter creds on returning visits. Also, I'm using restful_authentication, so I need to have this work within that context.
What is the best way to do this? I haven't been to find any tutorials on allowing the signup and authentication pieces. Most examples just show how to authenticate a Twitter user into your app.
Thanks.
I have a string of words; let's call them bad:
bad = "foo bar baz"
I can keep this string as a whitespace separated string, or as a list:
bad = bad.split(" ");
If I have another string, like so:
str = "This is my first foo string"
What's the fasted way to check if any word from the bad string is within my comparison string, and what's the fastest way to remove said word if it's found?
#Find if a word is there
bad.split(" ").each do |word|
found = str.include?(word)
end
#Remove the word
bad.split(" ").each do |word|
str.gsub!(/#{word}/, "")
end
I have two arrays:
x = [ [0, "#0"], [1, "#1"] ]
y = [ [00, "00 description"], [10, "10 description"] ]
What i need is to merge them so i get the following as result:
result = [ [000, "#0 00 description"], [010, "#0 10 description"],
[100, "#1 00 description"], [110, "#1 10 description"]]
Is there a method for that? Or I'll need to use collect or something like this?
Thanks in advance.
I started migrating from cucumber + webrat to cucumber + capybara. Now the behavior of "I should see " seems to be somewhat different. Most of these fail now, although I didn't change anything on the page. I replaced the snippet that should be found with some stuff that is on every page and for some text it works and for other text it doesn't. I can't find any pattern in what is found in the page's content and what is not.
Webrat used to print what the page content is that it found, in case it did not contain the required phrase. Is there anyway to have capybara show what text it got from the page in which it tried to find the text?
I'm trying to write a functional test. My test looks as following:
describe PostsController do
it "should create a Post" do
Post.should_receive(:new).once
post :create, { :post => { :caption => "ThePost", :category => "MyCategory" } }
end
end
My PostsController (a part of it actually) looks as following:
PostController < ActiveRecord::Base
def create
@post = Post.new(params[:post])
end
end
Running the test I'm always receiving a failure, which says that the Post class expected :new but never got it. Still, the actual post is created.
I'm a newbie to RSpec. Am I missing something?
It seems no class for input type 'submit' in font-awesome. Is it possible to use some class from font-awesome for button input? I've added icons to all buttons (which actually links with class 'btn' from twitter-bootstrap) in my applications, but can't add icons on 'input type submit'.
Or, how to use this code:
input#image-button{
background: #ccc url('icon.png') no-repeat top left;
padding-left: 16px;
height: 16px;
}
html:
<input type="submit" id="image-button">Text</input>
(which I took from HTML: How to make a submit button with text + image in it?) with font-awesome?
Hi. I aw working on cross site authentication (some domains have got common authentication). So I want to send authentication data (login, password) to main domain from others.
How should I use protect_from_forgery and how can I check if data received from valid domain?
What I am thinking now is to turn off protect_from_forgery for session controller and check domain name of received data.
But maybe I can configure CSRF protection for not only one domain?
Im using the gem for thinking sphinx:
sudo gem install freelancing-god-thinking-sphinx \
--source http://gems.github.com
So:
require 'vendor/plugins/thinking-sphinx/recipes/thinking_sphinx'
Which is prescribed on the website does not work.
How do I include the capistrano thinking sphinx tasks in my deploy.rb file when using the gem?
EDIT
Adding: require 'thinking_sphinx/deploy/capistrano'
gives me:
/usr/lib/ruby/gems/1.8/gems/freelancing-god-thinking-sphinx-1.1.12/lib/thinking_sphinx/deploy/capistrano.rb:1: undefined method `namespace' for main:Object (NoMethodError)
from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require'
from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:36:in `require'
from /usr/lib/ruby/gems/1.8/gems/capistrano-2.5.8/lib/capistrano/configuration/loading.rb:152:in `require'