Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old May 8, 2006, 10:32 PM   #1
white89gt
macrumors regular
 
Join Date: Jan 2006
Ruby on Rails database problem

Here's the problem. I build a new rails app, set up the access to the database , and scaffold the controller. Everything works fine. Then I start rebuilding the list.rhtml file. Once I'm done I can add, view, and edit any entries that I make but when I try to destroy them nothing happens. In short I can't figure out how to delete rows from the db. I'm using the exact same syntax as the original list.rhtml file but nothing happens. I've made sure that the user has the correct rights several times. What am I missing? I can post code if I need to.
white89gt is offline   0 Reply With Quote
Old May 8, 2006, 11:13 PM   #2
Rower_CPU
Moderator emeritus
 
Rower_CPU's Avatar
 
Join Date: Oct 2001
Location: San Diego, CA
Once you start customizing the scaffolding you often also need to go into the controller for the action and explicitly define your methods. Are you getting any errors (you're in development mode, I hope) or does the log have any info?

Please post code, too.
__________________
Join MacRumors.com - Team Folding!
Rower_CPU is offline   0 Reply With Quote
Old May 9, 2006, 03:55 AM   #3
demallien
macrumors regular
 
Join Date: Oct 2005
Quote:
Originally Posted by white89gt
Here's the problem. I build a new rails app, set up the access to the database , and scaffold the controller. Everything works fine. Then I start rebuilding the list.rhtml file. Once I'm done I can add, view, and edit any entries that I make but when I try to destroy them nothing happens. In short I can't figure out how to delete rows from the db. I'm using the exact same syntax as the original list.rhtml file but nothing happens. I've made sure that the user has the correct rights several times. What am I missing? I can post code if I need to.
Yup, I think you're going to need to post the code (both the .rhtml and the controller .rb). Whilst I can't claim to be a Rails expert, I have done a simple catalogue app that successfully deletes rows from the table.

As the first post says, I'm guessing that the problem is in the controller. Does your .rhtml send the correct message to the controller object? Does the controller object have the receiver defined?
demallien is offline   0 Reply With Quote
Old May 9, 2006, 09:45 AM   #4
white89gt
Thread Starter
macrumors regular
 
Join Date: Jan 2006
I figured it out. Here's what I was doing:

Quote:
<%= link_to 'Delete', :action => 'destroy', :id => @workorder %>
for some reason it won't work unless you add a confirm and a post like this

Quote:
<%= link_to 'Delete', { :action => 'destroy', :id => @workorder }, :confirm => "Are you sure", ost => true %>
I can't figure out how to diable smilies...the is actually a : followed by the word post.
I was using InstantRails a few days ago and then I downloaded the full blown deal and I guess there are some subtle differences.
white89gt is offline   0 Reply With Quote
Old May 9, 2006, 09:53 AM   #5
Rower_CPU
Moderator emeritus
 
Rower_CPU's Avatar
 
Join Date: Oct 2001
Location: San Diego, CA
Glad to hear you sorted it out.
__________________
Join MacRumors.com - Team Folding!
Rower_CPU is offline   0 Reply With Quote
Old May 10, 2006, 06:45 AM   #6
demallien
macrumors regular
 
Join Date: Oct 2005
Quote:
Originally Posted by white89gt
for some reason it won't work unless you add a confirm and a post like this

Hmmm, seems a little odd.

I know you have already got something to work, but the solution is not exactly obvious... So I'm going to suggest a couple of things...

Firstly, it's a bit odd that you have an instance variable, @workorder, in your rhtml code. Have you actually declared a class on the page???? That would be rather wierd, architecturally speaking. Classes are normally declared in a controller, or in a model, not in a view...

Secondly, did you try the original form of the command, except putting the braces around the hash, giving:
<%= link_to 'Delete', { :action => 'destroy', :id => @workorder }%>

My guess is that putting the braces around the hash somehow allows Rails to correctly deal with the '@', which it was unable to do without the braces. Is @workorder a vector maybe?
demallien is offline   0 Reply With Quote
Old May 10, 2006, 02:17 PM   #7
white89gt
Thread Starter
macrumors regular
 
Join Date: Jan 2006
Quote:
Originally Posted by demallien
Hmmm, seems a little odd.

I know you have already got something to work, but the solution is not exactly obvious... So I'm going to suggest a couple of things...

Firstly, it's a bit odd that you have an instance variable, @workorder, in your rhtml code. Have you actually declared a class on the page???? That would be rather wierd, architecturally speaking. Classes are normally declared in a controller, or in a model, not in a view...

Secondly, did you try the original form of the command, except putting the braces around the hash, giving:
<%= link_to 'Delete', { :action => 'destroy', :id => @workorder }%>

My guess is that putting the braces around the hash somehow allows Rails to correctly deal with the '@', which it was unable to do without the braces. Is @workorder a vector maybe?
The reason for the instance variable is because I moved the delete function from the list.rhtml to the show.rhtml file. When it is on the list page, the id is generated per line when the code is parsed. When it is on the show page, the only link to that particular instance is stored in the instance variable from the controller file. I know it isn't necessarily the best way to do it, but for the program that I'm building the delete function won't be needed in the end since I'm going to archive all closed workorders. I just kept it around so I could clean things up without having to rake the database.

And no, I didn't think to try <%= { link_to 'delete', :action => 'destroy', :id => @workorder }%> . I may give it a try, but I actually kind of like having to confirm the delete. That way I don't goof up.
white89gt is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
GW2 Database- iPhone and iPad database for Guild Wars 2 skoroapps iPad Apps 19 Jul 20, 2013 05:59 AM
GW2 Database - iPhone and iPad database for Guild Wars 2 skoroapps iPhone and iPod touch Apps 14 Jul 20, 2013 05:58 AM
How About Rails For $0.99? AppleRobert iPad Apps 0 Apr 2, 2013 10:37 AM
Ruby on Rails developing GimmeSlack12 Mac Programming 2 Nov 27, 2012 03:06 PM
Attendance app with a database problem leaf777 iPhone/iPad Programming 3 Nov 1, 2012 01:14 PM

Forum Jump

All times are GMT -5. The time now is 06:27 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC