I know that you can do something like this to load the rails environment:
task :my_task => :environment do
MyModel.find(1)
end
But it seems the code in the models are not executed. I am using acts_as_audited, and there is a nice class function which retrieves all models which are being audited. The call looks something like:
...
I execute the following commands to make the model:
script/generate model user firstname:string lastname:string
script/generate song group songname:string songtitle:string
a user has_many :songs and a song belongs_to :user
after this I run rake db:migrate however, the associations are not carried to my actual DB. Because in my actu...
Take this scenario. I have a Google Analytics tracking code, and I only want it to show up in Production mode. So I might have two scenarios like this:
Scenario: Don't embed tracking code in development or test mode
Given the app is not in production mode
When I go home
Then I should really not see the tracking code
Scenario: Emb...
I am new to Rails. In my web application, the user can type the contents of a file in a textarea or a content Editable iFrame and when he saves the file, the contents should be written to the file with the file extension specified by the user. How can I do so??
...
hi
I am using checkboxes, on clicking checkbox my partial page has to refresh. And partial page is displayed in thickbox.
I want to refresh it using ajax.
I am using code written below, but no page reload is happening
respond_to do |format|
format.js{ render :update do |page|
page.replace_html :content, :partia...
I thought I was following this RoR tutorial to a T, but apparently not. They instructed that we write this code into apps/views/index.html.erb
<h1>Listing posts</h1>
<table>
<tr>
<th>Name </th>
<th>Title </th>
<th>Content </th>
</tr>
<% for post in @posts %>
<tr>
<td><%=h post.name %...
In the documentation of cancan it shows how to fetch all accessible records (in http://wiki.github.com/ryanb/cancan/fetching-records) in this way:
@articles = Article.accessible_by(current_ability)
but what is current_ability? I've tried passing the current user which I'm using for authentication and authorization, but I've got this e...
if the HAML is:
.class1
.class2
.class3
%div
content... many lines
How can it be made so that it doesn't respond with class1 and class2 if it is Ajax?
- if !request.xhr?
.class1
.class2
.class3
%div
content... many lines
won't work, because if not Ajax, then class3 is not a child of class2. It mi...
I am creating a survey application so I created a surveys controller that behaves very restfully creating, updating, etc a Survey. However now I'm adding other actions to it like 'take', for taking a survey, and 'share', for sharing a survey. There are more actions too. I'm starting to wonder if I should organize my code differently a...
I'm actually brand new to Ruby and Sybase both, but here goes:
I'm trying to connect Ruby up to a remote Sybase server. (I've been successful with a local MySQL server.)
I've done:
gem install sqlanywhere
gem install activerecord-sqlanywhere-adapter
(and set up the stuff in the database.yml, of course)
Still, when I got to http://...
Hello, I have a couple iPhone apps talking to one ruby on rails server. I have been using the apn_on_rails gem by mark bates/PRX (http://github.com/PRX/apn_on_rails) to offer push notifications to both apps.
The README specifies how to support one app, but I need to support two apps. Not only that, but I would like to send out these not...
Hi All,
I want a search functionality in my application for the data like following
topic_id tag
1 cricket
1 football
2 football
2 basketball
3 cricket
3 basketball
4 chess
4 basketball
Now when i search for term cricket AND football o/p should be
topic_id
...
I use the following code to render a template to a string that I can use later on:
renderer = ActionView::Base.new(MyApp::Application.config.view_path)
# INCLUDE HELPERS HERE
data = renderer.render(:partial => template, :locals => locals)
However, I want to be able to access some helpers (actually all). In rails 2.3 I was able to do t...
I have events and users/teams.
class Event
has_many :users, :through => :registrations
end
class User
has_many :events, :through => :registrations
end
class Registration
belongs_to :users
belongs_to :events
end
When I register a user, I'm connecting them to the event like so:
@event.users << @user
Does this implicitly creat...
I'm switching to RoR from ASP.NET MVC. Yeah, migrations are cool, but I do not need to use different databases in my web applications. Postgresql will do just fine.
So is it okay if I use PGAdmin to create and administer my databases and schema and avoid all these fancy migrate, rake etc?
Update
Thanks everyone! Now I better understa...
I moved some files into subfolders within my app/models directory and added those directories in the config.load_paths in config/environment.rb:
config.load_paths += Dir["#{Rails.root}/app/models/extras"]
within app/models/extras I've got a few ActiveRecord models, for instance say:
app/models/extras/blog_post.rb
class BlogPost < Ac...
I've gone through the docs in github: http://github.com/outoftime/sunspot to find solutions for highlighting, but it doesn't seem to work for me.
My Job model has something like this block (omitted some fields on purpose):
searchable do
text :name
string :name, :stored => true
time :updated_at
time :created_at
t...
I have an association one to many from foo and bar.
i do a foo.to_json(:include => :bar) but i want to display not all the rows of bar, but only the last, how to do?
...
I need to learn a language for writing web applications (not websites!).
After some research in google and stackoverflow I ended up that the choice should fall in:
1) Ruby + Rails
2) Python + Django
3) c# + ASP.NET
For sure even pickng one randomly would not be a bad choice, but my question here is specific to UI controls. I come fr...
I think the code is more explicit
option A
class RedirectController < ApplicationController
def index
redirect_to :controller => 'posts', :action => 'show', :id => 1
# it works
end
end
option B
class RedirectController < ApplicationController
def index
render :controller => 'posts', :action => 'show', :id => 1
...