INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

can't save form select option to database

can't save form select option to database

(OP)
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

RE: can't save form select option to database

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

"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)

RE: can't save form select option to database

(OP)
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

RE: can't save form select option to database

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?

RE: can't save form select option to database

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

"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)

RE: can't save form select option to database

(OP)
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

RE: can't save form select option to database

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?

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close