# Please help!

**URL:** <https://www.ruby-forum.com/t/please-help/80587>\
**Category:** Rails\
**Created:** [November 30, 2005, 1:47pm UTC](https://www.ruby-forum.com/t/please-help/80587 "2005-11-30T13:47:30Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![dannypotta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a9adbd/32.png) [@dannypotta](https://www.ruby-forum.com/u/dannypotta)\
**Post date:** [November 30, 2005, 1:47pm UTC](https://www.ruby-forum.com/t/please-help/80587/1 "2005-11-30T13:47:30Z")

</div>

Hi,

I’m very new to Ruby and to Rails and I’m trying to get to grips with  
it. One of things I’m trying to do is to build a very simple web  
application where, essentially, people can look up films and post  
reviews about the films.

I’ve created a database in MySQL with a Reviews table which includes  
table columns: id, review\_text, person\_id and film\_id. id is the  
primary key, Person\_id and film\_id are foreign keys that I’m trying to  
pass into that table.

Can anyone please, please tell me what syntax I need to use in the  
VIEW in order to pass all of the data to the controller and save it in  
the database? Some of my code is below - I haven’t yet built a person  
login so I’ve simply assigned a person\_id. I’ve seem to have tried  
every random bit of syntax I can think of and review\_text gets submitted  
but I can’t pass person\_id or film\_id so it won’t save in the database.

EXTRACTED CODE FROM VIEW

\<%= @film.id %\>  
\<%= @person.id = 22 %\>

```
<%= start_form_tag :action => "create_review", :id => @film %>
	<p>&nbsp;</p>
	<p><b>Review it:</b></p>
	<p><%= text_area "review", "review_text" %></p>
	<p>&nbsp;</p>
	<%# "film_id" = @film.id %>
	<%# "person_id" = @person.id %>
	<%= submit_tag "create" %>
</form>

```

EXTRACTED CODE FROM CONTROLLER

def add\_review  
#@review = Review.new (params[:review])  
@person = Person.new  
@film = Film.find(params[:id])  
end

def create\_review  
@review = Review.new(params[:review])  
if @review.save  
flash[:notice] = ‘review was successfully created.’  
redirect\_to :action =\> ‘view\_review’  
else render :action =\> ‘new\_review’  
end  
end

---

<div class="post-metadata">

**Author:** ![dannypotta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a9adbd/32.png) [@dannypotta](https://www.ruby-forum.com/u/dannypotta)\
**Post date:** [November 30, 2005, 2:20pm UTC](https://www.ruby-forum.com/t/please-help/80587/2 "2005-11-30T14:20:00Z")

</div>

Hi Daniel -

For starters I don’t see in your form how your film\_id and person\_id  
are going to get passed into the action since they’re not form fields  
(and they’re commented out). Your scenario is kind of half baked at  
the moment but to help in getting it working at the minimum you should  
have those two id fields stored in a field  
in rails you do this with:  
hidden\_field(:variable, :attribute, options)

Also I’m not sure why you’re start\_form\_tag has an :id =\> @film in it.  
That’s not doing anything but I’m not sure what you were trying to  
do.

I would also suggest that you actually create the model objects that  
you’re going to be using in the real world so you’re not creating  
problems due to an unimplemented model.  
script/generate scaffold will make this very easy to test.

Mike

---

<div class="post-metadata">

**Author:** ![dannypotta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a9adbd/32.png) [@dannypotta](https://www.ruby-forum.com/u/dannypotta)\
**Post date:** [November 30, 2005, 2:24pm UTC](https://www.ruby-forum.com/t/please-help/80587/3 "2005-11-30T14:24:04Z")

</div>

Hi, Daniel,

IMHO you’re approaching this thing from the wrong side. Why are you  
working on the review-component while your film-component seems to be  
not up at all? In your design a film seems to be the central model. You  
should model a film- and a review-model as it is explained on the  
community sites or in Agile Web D. with rails. A film then  
should have a one to many relationship to the review-model. Once you’ve  
got this up you might create some test-data through the scaffolded  
admin-view and then you might add reviews to that film. This is exactly  
the same as DHH does in the introduction video with articles (~films)  
and comments (~reviews), so just have a look at that video and you  
should get the idea.

regards  
Jan

---

<div class="post-metadata">

**Author:** ![dannypotta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a9adbd/32.png) [@dannypotta](https://www.ruby-forum.com/u/dannypotta)\
**Post date:** [November 30, 2005, 2:28pm UTC](https://www.ruby-forum.com/t/please-help/80587/4 "2005-11-30T14:28:07Z")

</div>

On 30.11.2005, at 15.19, Michael E. wrote:

> Also I’m not sure why you’re start\_form\_tag has an :id =\> @film in it.  
> That’s not doing anything but I’m not sure what you were trying to  
> do.

Actually, it does. It passes the id of the @film to the receiving  
action so that it can be used as params[:id]. This all assuming that  
the @film is a valid and saved Film object. So when using this you  
won’t have to use a hidden field for the film id.

//jarkko

---

<div class="post-metadata">

**Author:** ![dannypotta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a9adbd/32.png) [@dannypotta](https://www.ruby-forum.com/u/dannypotta)\
**Post date:** [November 30, 2005, 2:36pm UTC](https://www.ruby-forum.com/t/please-help/80587/5 "2005-11-30T14:36:17Z")

</div>

Couldn’t the form tag be written

\<%= form\_remote\_tag :url =\> { :action =\> :someControllerMethod,  
:filmid=\>@film.id, :personid=\>@person.id }%\>

That should allow you to refer to params[:filmid] and params[:personid]  
in the controller.

John

---

<div class="post-metadata">

**Author:** ![dannypotta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a9adbd/32.png) [@dannypotta](https://www.ruby-forum.com/u/dannypotta)\
**Post date:** [November 30, 2005, 3:29pm UTC](https://www.ruby-forum.com/t/please-help/80587/6 "2005-11-30T15:29:12Z")

</div>

Michael beat me to the answer, but I’d just like to throw in an extra  
two pieces of advice:

1. Email subject lines should describe the subject of your email. A  
subject like “PLEASE HELP!” might not get read by the right person  
where a subject like “How do I pass data from views to controllers?”  
would.

2. Use \<%= end\_form\_tag %\> to close your form.

## Yours, Craig

Craig W. | t: +44 (0)131 516 8595 | e: removed\_email\_address@domain.invalid  
[Xeriom.NET](http://Xeriom.NET) | f: +44 (0)709 287 1902 | w: [http://xeriom.net](http://xeriom.net)

---

<div class="post-metadata">

**Author:** ![dannypotta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a9adbd/32.png) [@dannypotta](https://www.ruby-forum.com/u/dannypotta)\
**Post date:** [November 30, 2005, 4:37pm UTC](https://www.ruby-forum.com/t/please-help/80587/7 "2005-11-30T16:37:53Z")

</div>

Thanks very much all. I think I’ll watch the video first and then  
try each of the various suggestions in turn. As I said, I’m very new  
to rails and still have very little clue what I’m doing but I guess I’ll  
learn by trying.

Thanks again,  
Danny
