Hi,
could you tell me please - how to use method create_translation_table! of globalize2 with additional options such as :null = false, :default = "abc" ???
I am trying to dynamically define methods based on xml mappings. This works really well. However I want to create an instance variable that is a array of the dynamically defined methods.
My code looks something like this
def xml_attr_reader(*args)
xml_list = ""
args.each do |arg|
string_val = "def #{arg}; " +
" xml_mapping.#{arg}; " +
"end; "
self.class_eval string_val
xml_hash = xml_list + "'#{arg}',"
end
self.class_eval "@xml_attributes = [] if @xml_attributes.nil?;" +
"@xml_attributes = @xml_attributes + [#{xml_list}];" +
"puts 'xml_attrs = ' + @xml_attributes.to_s;" +
"def xml_attributes;" +
" puts 'xml_attrs = ' + @xml_attributes.to_s;" +
" @xml_attributes;" +
"end"
end
So everything works except when I call xml_attributes on an instance it return null (and prints out 'xml_attrs = ').
While the puts before the definition actually prints out the correct array. (when I instantiate the instance)
I would like to do the following:
<% f.fields_for :blind_dates do |bdf| %>
<%= render :partial => bdf %>
<% end %>
Which is cool. The problem is I want to have a link "add another blind date" which will use the same partial, but add a new one dynamically to the page.
How do I do this? Is there documentation that you have a link to?
Hi,
I have a table called 'choices' in this table i am storing static data for my site like Blood Groups , qualification, job types etc., I have to create rake tasks one is for to create backup choices.sql file from choices table data, second one is dump the data from .sql file to choice table. How can I create the rake tasks.
Any other best way to take backup data from a table and load data into the table
Thanks
I've been trying to do SEO friendly urls, and managed to get it work, but when I call index action on blogs, I get a weird "undefined method `parameterize' for nil:NilClass." The method works when using show method.
def to_s
title
end
def to_param
"#{id}-#{to_s.parameterize}"
end
Normally to pass parameters via in RSpec we do:
params[:my_key] = my_value
get :my_method
Where my_method deals with what it received from params. But in my controller I have a method, which takes args directly i.e.:
def my_method(*args)
...
end
How do I call the method with those args from within the test? I've tried get :my_method(args) but Ruby interpreter complains about syntax error.
I used a global variable in my app for passing information before. But I got a problem and thanks everyone here suggested me to store those data in session with database.
I tried, but I found that I can't access the session variable in Model. I googled and knew this is the Model normal behavior, RoR won't pass the session variable to Model.
So
how to pass the value of the
session variable into Models? or
is there any other method for my
use case? I need a variable storing
a value, which is required in all
MVCs, and should be independent
between different concurrent users.
Thanks everyone. :)
I currently have a form like this:
<% form_for @stem, :html => {:multipart => true} do |f| %>
<%= f.file_field :sound %>
<% end %>
This outputs (essentially):
<form method="post" id="new_stem" class="new_stem" action="/stems">
<input type="file" size="30" name="stem[sound]" id="stem_sound">
</form>
However I'm planning to use jQuery's ajaxForm plugin here and would like the new stem to be returned in JSON format. I know if the form's action was "/stems.json" this would work, but is there a parameter I can put into the form_for call to ask it to return JSON?
I tried doing
<% form_for @stem, :html => {:multipart => true, :action => '/stems.json'} do |f| %>
but this didn't appear to work.
When I try to pull down a database while at work I get the following error:
:>heroku db:pull
Auto-detected local database: sqlite://db/development.sqlite3
Bad credentials given for http://heroku:[hidden]@taps.heroku.com
Note that when I am at home I am able to run this command just fine. I wanted to know if you have any suggestions for common reasons I would get this error.
Using Spreadsheet GEM, I am able to read xls files in development environement.
As I move to production server, application is unable to read xls files.
Please help what can be the likely changes I am missing on to make it work in production environment too.
Thanks in advance
I use Ultrasphinx gem plugin as a wrapper for accessing Sphinx search daemon.
My model declaration:
class Foo < ActiveRecord::Base
is_indexed :fields => ['content', 'private_notes', 'user_id']
Client code:
filters = {}
if type == "private"
# search only in `content` column
filters['user_id'] = current_user.id
else
# search in `content` and `private_notes` columns
end
results = Ultrasphinx::Search.new(:query => params[:query],
:per_page => 20,
:page => params[:page] || 1,
:filters => filters)
The problem I have now with Ultrasphinx gem(or Sphinx, in general?) is that it does not allow me to change set of fields where to look for matches IN RUNTIME
How can I solve this problem?
Hi, Here is my scenario:
I have three models Subscriber, Subscription, Plan, with has_many :through relationship
between Subscriber and Plans.
A subscriber can have multiple plans with one active plan. Whenever a subscriber selects a plan I save it using accepts_nested_attributes_for :subscriptions. I get one plan from the form.
Now my problem is I want to get the ID of the record created in subscriptions table.
When building the following factory:
Factory.define :user do |f|
f.sequence(:name) { |n| "foo#{n}" }
f.resume_type_id { ResumeType.first.id }
end
ResumeType.first returns nil and I get an error.
ResumeType records are loaded via fixtures. I checked using the console and the entries are there, the table is not empty.
I've found a similar example in the factory_girl mailing list, and it's supposed to work.
What am I missing? Do I have to somehow tell factory_girl to set up the fixtures before running the tests?
Hi,
I'd like my Search form to return the following url after submit:
/anuncios/buscar/the_text_I_searched
My form is the following:
<% form_for :announcement, :url => search_path(:txtSearch) do |f| %>
<div class="searchBox" id="basic">
<%= text_field_tag :txtSearch, params[:str_search].blank? ? "Buscá tu curso rápido y fácil." : params[:str_search], :maxlength=> 100, :class => "basicSearch_inputField", :onfocus => "if (this.value=='Buscá tu curso rápido y fácil.') this.value=''", :onblur => "if(this.value=='') { this.value='Buscá tu curso rápido y fácil.'; return false; }" %>
<div class="basicSearch_button">
<input type="submit" value="BUSCAR" class="basicSearch_buttonButton" />
<br /><a href="#" onclick="javascript:jQuery('#advance').modal({opacity:60});">Busqueda avanzada</a>
</div>
</div>
<% end %>
My routes' line for search_path is this:
map.search '/anuncios/buscar/:str_search', :controller => 'announcements', :action => 'search'
Well, this will work if I manually type the url I want in the brower, but definitely, if you look at the form's url, you'll find a ":txtSearch" parameter, which is not giving me the actual value of the text field when the form is submitted. And that's what I'd like to get!
Could anybody help me on this?
Hey ,Guys!
I want to use the method request.query_string to send the key-value to the controller,how can i use in the sentences;
=link_to 'excel' , reports_excel_path(:format => 'xls',:from => 'conversations')
Thank you!
I have an array containing several students. I want them to cross-grade one another randomly, i.e. each student will grade someone and will be graded by someone else (these two people may or may not be the same person).
Here is my working solution. I'm sure there is a more elegant answer!
def randomize(student_array)
graders = student_array.dup
gradees = student_array.dup
result = {}
graders.each do |grader|
gradee = grader
while gradee == grader
gradee = gradees.sample
end
result[grader] = gradee
gradees.delete_at(gradees.index(gradee))
end
return result
end
This is my code:
[email protected] do |a|
-if @i%3 == 0
%ul
%li=link_to a.name, a
-@i += 1
I need the li to be inside the ul which is inside the if-statement.
I can't do it because of the indentation. Can't I just tell the li to indent automatically?
Thanks
Im trying to get a controller to create a new account with the user id filled in, this doesn't work in my controller or in the console, why? Any suggestions on how to implement this would be much appreciated.
class PaymentNotification < ActiveRecord::Base
after_create :add_account_to_market
private
def add_account_to_market
if status == "Completed"
line = LineItem.find(:first, :conditions => { :cart_id => cart.id })
line.quantity.times do
Account.new(:user_id => cart.user_id)
end
end
end
end
I've just installed a ZenTest to use autotest in my project. I use rspec and have an integration folder inside it. As I don't want all my integration tests run every single time I start autospec , so I'd like to somehow restrict autospec from running tests in that folder.
How do I exclude a chosen folder inside a /spec from running by autotest?
I'm getting the following error:
Unknown action
No action responded to show. Actions: activate, destroy, index, org_deals, search, and suspend
Controller:
class Admin::HomepagesController < Admin::ApplicationController
def org_deals
@organization = Organization.find(:all)
end
Routes:
admin.resources :organizations, :collection => {:search => :get}, :member => {:suspend => :get, :activate => :get}
To note: This is a controller inside of a controller.
Any ideas why this is?
The idea would be to replace ERB with templates that are pure XHTML and that the view would be pure code manipulating the template content.
Have this been done already ?
My path helpers (like data_path, users_path) are now translating itself to use '.' instead of '/'.
For example, data_path(@data) translates to:
data.%23<datareport:0x7fcaba0c2970>
instead of '/data/id'.
My routes look like:
map.resources :data
I want to add additional criteria to the LEFT OUTER JOIN generated by the :include option in ActiveRecord finder.
class Post
has_many :comments
end
class Comment
belongs_to :post
has_many :comment_votes
end
class CommentVote
belongs_to :comment
end
Now lets say I want to find last 10 posts with their associated comments and the up comment votes.
Post.find.all(:limit => 10, :order => "created_at DESC",
:include => [{:comments => :comment_votes])
I cant add the condition to check for up votes as it will ignore the posts without the up votes. So the condition has to go the ON clause of the JOIN generated for the comment_votes. I am wishing for a syntax such as:
Post.find.all(:limit => 10, :order => "created_at DESC",
:include => [{:comments => [:comment_votes, :on => "comment_votes.vote > 0"])
Have you faced such problems before? Did you managed to solve the problem using the current finder? I hope to hear some interesting ideas from the community.
PS: I can write a join SQL to get the expected result and stitch the results together. I want to make sure there is no other alternative before going down that path.
How can I translate this SQL into a named_scope? Also, I want the total comments param to be passed through a lambda.
"select users., count() as total_comments from users, comments where (users.id = comments.user_id) and (comments.public_comment = 1) and (comments.aasm_state = 'posted') and (comments.forum_user_id is null) group by users.id having total_comments 25"