Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

can't save form select option to database 1

Status
Not open for further replies.

comboy

Instructor
May 23, 2003
226
Hi all,

First I'm new to ROR (stated today ) and I've googled abit to see if I could sort this out but I'm drawing a blank.

I'm using bitnami rubystack and netbeans 6.8, I have two tables movies and durations which I used netbeans to create the scaffolds for. I then edited the movies table to include a foreign key reference to the durations table and edit both models to include has_many and belongs_to

The problem seems to be with the code below (the new.html.erb) as it will not save the selected duration as I can't figure out where to include the :runningtime attribute.

Code:
<h1>New movie</h1>
<% form_for(@movie) do |f| %>
  <%= f.error_messages %>
  <p>
    <%= f.label :name %><br />
    <%= f.text_field :name %>
  </p>
  <p>
    <%= f.label :info %><br />
    <%= f.text_area :info %>
  </p>
  <p> <label for="Movie_runningtime">Please select the running time</label><br/>
<%= select("movies","runningtime", Duration.find(:all, :order=>"showlength DESC").collect {|d| [d.showlength, d.id]})%>
  </p>
 
  <p>
    <%= f.submit 'Create' %>
  </p>
<% end %>
<%= link_to 'Back', movies_path %>

All help appricated
 
Not sure I can help you with your question, but your table design seem wrong. There is (as far as I can see) a 1:1 relationship between movies and running times, so why not just hold the running time on the movies table? I can see that the "director's cut" or extended versions with previously deleted scenes might be longer or shorter, but surely these would count as different movies? Unless you want a movie table linked to a version or edition table which has the running time.

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::perlDesignPatterns)[/small]
 
Hi stevexff

I've actually sorted thee issue, the first parameter for the select statement should have been "movie" not "Movies".

In relation to the design the table is for a mock up of an entertainment site such as what movies are on at your local cinema.
The durations table will also be used for a plays table etc.


Graham
 
I don't think you really grasp the concept of relational database. The duration should really be in the 'movies' or 'plays' table as a field.
Actors, on the other hand, should definitely be in a separate table because they can be linked to separate roles and are altogether different entities.

Tao Te Ching Discussions : Chapter 9 (includes links to previous chapters)
What is the nature of conflict?
 
Indeed. Having an Actors table would be wrong too - a People table would be better, linked to the Movie by a many-to-many link with a role type. So then Clint Eastwood (for example) can be linked to his movies multiple times, with separate roles for Actor, Director, and Producer.

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::perlDesignPatterns)[/small]
 
Thanks for the replies guys I understand what you are both saying about the relationships but I'm just trying to learn ruby and it was a quick mock up to try and learn about how ROR handles foreign keys etc.

Thanks.


Graham
 
Comboy, when it comes to RoR, you'll quickly learn that if you form a sentence like this:
"xxxx BUT yyyy", then you had better have a darn good reason for the 'but'. RoR focuses on Convention over Configuration, so things are set up with "Sensible Defaults" ;)

Tao Te Ching Discussions : Chapter 9 (includes links to previous chapters)
What is the nature of conflict?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top