I want to get the auto incrementing id column for a create_table rails command to start at 500.
I've found examples of how to set the initial auto_increment id value in sql:
CREATE TABLE student ( id int(2) NOT NULL auto_increment, name varchar(50) NOT NULL default '', class varchar(10) NOT NULL default '', mark int(3) NOT NULL default...
I am trying to add multiple HABTM relationships through ActiveResource, but I am running into a lot of trouble. It seems that in a traditional rails app (i.e. all ActiveRecord), you can simply set your HABTM ids, and do something as such:
habtm = {:category_ids => [1,2,3]}
article.update_attributes(habtm)
Unfortunately, when I try to...
Hello, is there a gem or plugin that will populate a database with test data?
...
How would I store a pdf in my Rails app so that users can access/download them?
In my migration, would i i use the datatype t.binary?
Then in my controller/view, how should I present this data?
...
This is probably a stupidly easy question for a Rails person but is causing me no end of confusion. I downloaded several open source Rails projects but am not able to run them. Usually, are you supposed to do a db:migrate before you try to run a Rails project? I thought they were supposed to just run.
...
Hi,
I want to prevent users from signing up with a password = login for security reasons. I tried something like this:
validates_each :password do |record, attr, value|
if(value == self.login)
record.errors.add(attr)
end
end
But I always get the following error: undefined method login for self. It has something to d...
I've got two small structural issues that I'm not sure how to handle given my relative newbie-ness with RoR.
First issue: In one of my views, I have code that looks like this:
<ul style="list-style-type: circle">
<li><%= @apples.size %> apples</li>
<li><%= @oranges.size %> oranges</li>
<li><%= @bananas.size %> bananas</li>
<li>...
I am new to rails and trying to do a little refactoring (putting a partial renderer that lists titles in app/views/shared ) The renderer shows the dates along with the titles. However different users of the renderer use different dates. Part way through refactoring I have
title_date = list_titles.created_on
For the other user of the r...
Designing a web app with a admin section and a public facing section. It feels like having a public facing controller just for "index" and "show" is a bit redundant. All the suggestions I've read suggest a namespace for admin, which is fine. I just wonder if I should have one controller with an addition action, say "list_public" or somet...
I am always trumped by this question when starting a new project. When I look at examples like Mephisto, Typo, etc. they route their root to a controller that relates to a specific resource/model.
My problem is, almost every website I've ever built, I feel like my front page is actually a collaboration of all my models, and I can't see ...
Throughout our site there's a common model, let's say Video, that has a number of attributes like private/public/pending, downloadable, etc.
Based on the controller, action, request parameters and current user, we want to filter out particular videos from display. For instance, on the homepage we only want to show videos that are public...
I have a model, target, that holds a number of records that are timestamped. On the corresponding controller, I list the months of those records by doing the following:
In models/target.rb
def month
self.recorded_on.strftime('%B')
end
In controllers/targets_controller.rb
@records = Target.find :all
In views/targets/index.html....
My application currently has a very simple URL layout:
map.resource :account, :controller => "users", :only => [:show, :update, :destroy]
map.resources :workouts do |workout|
workout.resource :chart, :only => [:show]
workout.resources :taggings, :only => [:destroy, :create]
end
Giving me nice easy urls for the current user.
I'm...
I have just started investigating using more advanced models in Rails. One that I use regularly, with great success, is model where a many-to-many cross-reference relationship is accessed by a class that itself is a sub-class of the base class in the many-to-many relationship.
This way the cross-reference class can act as a stand-in for...
Rails is returning the wrong date from my database records. For my model ("Target"), if I run in script/console:
Target.find :all
I get all my records with the "recorded_on" field reading dates from "2000-01-01 xx:xx:xx".
If I take the same database and run in the sqlite3 console:
SELECT * FROM targets;
I get all my records with ...
I am trying to create an ActiveRecord model called 'Search' without a table. I keep getting this error when I do @search = Search.new.
sql::Error: Table 'searchdemo_development.tablelesses' doesn't exist: SELECT * FROM tablelesses
I am using the idea from this comment: http://stackoverflow.com/questions/315850/rails-model-without-dat...
I've got a table of what I call resources, want to show in a jquery dialog a particular record when user clicks button in a row.
in the table I'm doing:
<td><%=button_to_function 'Show','showresource1()',:class =>"ui-button ui-state-default ui-corner-all", :id => resource.id %></td>
then in javascript I want to pass jQuery dialog the...
I am attempting to use form_for to implement a search form that works with a table-less Search model I created. The search form keeps triggering the 'index' action. I assume I should use 'new' to create the form and 'create' the process the search query. Looking at the log, my POST is getting changed into a GET. Here's my code:
/searche...
I'm playing with the authlogic-example-app and I'm failing to get the email address from the OpenID provider (in my case: Google and Yahoo) when I register a user, resp. I get an empty response instead of an email address (check the comments in code below).
This is how my user model looks like (everything else looks like the "with_openi...
Say you have an Events model that contains information about the event. But what about things like slugs, titles and meta description that would go into the html?
It would seem like such things properly belong as attributes to a Page model rather than to an Events model.
Is there a correct way to do this? What are the pros and cons of...