Problem z script/generate scaffold

Ucze sie od niedawna railsow , przerabiam wprowadzenie do ruby on rails , mam problem z 4 rozdzialem rusztowania -
w ksiazce uzywaja dynamicznego scaffoldu ja zrobilem sobie statyczne poniewaz jade na rails 2.3.3

wykonalem ruby script/generate scaffold Photos ale niestety dostaje blad:

uninitialized constant PhotosController::Photos

bylbym bardzo wdzieczny za jakas pomoc , pozdrawiam

spróbuj w liczbie pojedynczej np.:

ruby script/generate scaffold photo name:string

pokombinuje tylko kurde teraz mam problem z usunieciem tego rusztowania cos mi nie chce usunac

damian-kaleks-computer:photos kalek$ ruby script/destroy scaffold Photos
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.3/lib/active_support/dependencies.rb:443:in load_missing_constant': uninitialized constant RespondsToParent (NameError) from /Library/Ruby/Gems/1.8/gems/activesupport-2.3.3/lib/active_support/dependencies.rb:80:inconst_missing’
from /Library/Ruby/Gems/1.8/gems/activesupport-2.3.3/lib/active_support/dependencies.rb:92:in const_missing' from /Users/kalek/rubydev/photos/vendor/plugins/active_scaffold/environment.rb:7 from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:ingem_original_require’
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in require' from /Library/Ruby/Gems/1.8/gems/activesupport-2.3.3/lib/active_support/dependencies.rb:156:inrequire’
from /Library/Ruby/Gems/1.8/gems/activesupport-2.3.3/lib/active_support/dependencies.rb:521:in new_constants_in' from /Library/Ruby/Gems/1.8/gems/activesupport-2.3.3/lib/active_support/dependencies.rb:156:inrequire’
… 15 levels…
from /Users/kalek/.gem/ruby/1.8/gems/rails-2.3.3/lib/commands/destroy.rb:1
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in gem_original_require' from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:inrequire’
from script/destroy:3

dzieki wielkie za pomoc , dziala tyle ze np lista zdjec jest pusta choc w bazie w tabeli photos sa zdjecia i powiny sie wyswietlic nazwy plikow , moze wiesz czemu sie nie wsyweitl dziwne , ale pokombinuje dalej , jeszcze raz dzieki , pozdro ,

jakbys mogl to napisz jak niszczyc scaffold bo ten destroy mi cos nie poszedl ,utworzylem od nowa projekt

Hmm dziwi mnie tez fakt ze generate scaffold photo nie utworzyl akcji list zobacz na kod

class PhotosController < ApplicationController

GET /photos

GET /photos.xml

def index
@photos = Photo.all

respond_to do |format|
  format.html # index.html.erb
  format.xml  { render :xml => @photos }
end

end

GET /photos/1

GET /photos/1.xml

def show
@photo = Photo.find(params[:id])

respond_to do |format|
  format.html # show.html.erb
  format.xml  { render :xml => @photo }
end

end

GET /photos/new

GET /photos/new.xml

def new
@photo = Photo.new

respond_to do |format|
  format.html # new.html.erb
  format.xml  { render :xml => @photo }
end

end

GET /photos/1/edit

def edit
@photo = Photo.find(params[:id])
end

POST /photos

POST /photos.xml

def create
@photo = Photo.new(params[:photo])

respond_to do |format|
  if @photo.save
    flash[:notice] = 'Photo was successfully created.'
    format.html { redirect_to(@photo) }
    format.xml  { render :xml => @photo, :status => :created, :location => @photo }
  else
    format.html { render :action => "new" }
    format.xml  { render :xml => @photo.errors, :status => :unprocessable_entity }
  end
end

end

PUT /photos/1

PUT /photos/1.xml

def update
@photo = Photo.find(params[:id])

respond_to do |format|
  if @photo.update_attributes(params[:photo])
    flash[:notice] = 'Photo was successfully updated.'
    format.html { redirect_to(@photo) }
    format.xml  { head :ok }
  else
    format.html { render :action => "edit" }
    format.xml  { render :xml => @photo.errors, :status => :unprocessable_entity }
  end
end

end

DELETE /photos/1

DELETE /photos/1.xml

def destroy
@photo = Photo.find(params[:id])
@photo.destroy

respond_to do |format|
  format.html { redirect_to(photos_url) }
  format.xml  { head :ok }
end

end
end

nie ma w tym nic dziwnego, tak ma być.

najgorsze ze wszystko jesy puste nie wyswietla z bazy nic , rozumiem ze nie widzi modelu bo zrobilem

generate scaffold Photo i nie podalem zadnych kolumn itd ale chcialbym zeby wzial sobie strukture z modelu ale jak robie
generate scaffold Photo Photo to mowi ze wrong number of arguments (1 for 2)

czytam o rails dopiero od jakiegos tygodnia i jeszcze wszystkie nie lapie , moze ktos mi troche moglby wyjasnic jak zrobic zeby to mialo rece i nogi :slight_smile:

@kalek: script/destroy nie zadziałał bo plugin active_scaffold powodował błędy, spróbuj w tamtym projekcie odpalić rake gems:install, a później:

script/destroy scaffold Photos --force-plural

masz akcję index, a nie list :slight_smile:

Przerzuć się na książkę opisującą railsy w wersji 2, np.
http://www.pragprog.com/titles/rails3/agile-web-development-with-rails-third-edition
albo chociaż poradnik online
http://guides.rubyonrails.org/

Co do ostatniego postu to poczytaj o scaffoldzie w rails 2 i o migracjach, tabel w bazie nie tworzysz ręcznie tylko za pomocą migracji.

pzdr

niestey nie znam agnielskiego jakos musze sie przemezyc , poza tym kupilem 2 ksiazki wlasnie niedawano i chce je przeroic do konca , jak skoncze to moze kupie nawet angielska i bede sie uczyl dzieki za pomoc , pozdroo , musze skumac dobrze to scaffold :slight_smile:

Pewnie dla was to smieszne ale jezeli moglibyscie pomoc ,
zrobilem sobie scaffold Photo , jest tylko ze tak jak mowie pusty , jak moge zrobic zeby mi odczytal dane z bazy modyfikuje widok index na cos takiego

dodalem to -

<%= puts @photo %> ale nic nie nadaje jak zrobie @photo.filename to mowi ze nie widzi metody filename
a w ksiazce pisza i ze dziala , kurde nie moge zczaic , jak moze ktos pomoc choc troche,

Listing photos

<% @photos.each do |photo| %>

<% end %>
<%= puts @photo %> <%= link_to 'Show', photo %> <%= link_to 'Edit', edit_photo_path(photo) %> <%= link_to 'Destroy', photo, :confirm => 'Are you sure?', :method => :delete %>

<%= link_to ‘New photo’, new_photo_path %>

utworzylem tabele poprzez migracje

do zabaw z fotkami jest paperclip

ok udalo mi sie zrobilem generrate scaffold Photo filename:string , juz zalapalem , niestety te stare ksiazki opisuja rails 1 cos i sa roznice ale chce przerobic te cale ksiazki skoro je kupilem , a pozniej przerobie sobie tego gudie i poczytam o scaffold w rails 2, dzieki wielkie chlopacy za pomoc , jakby ktos mial
problemy z Photoshopem to sluze pomoca , ja jestem grafikiem :slight_smile: ale chce tez zostac teraz programista , chce wlasnie napisac magisterke w rails , przedemna dluga droga , dzieki pozdroo

czytaj i pytaj

l0pez pisales czytaj i pytaj wiec pisze ,

mam taki problem ze chce zrobic migracje ale wywala mi: Mysql::Error: Table ‘slides’ already exists: , ok rozumiem ze istnieje i nie moze jej utworzyc
wiec robie rake db:migrate VERSION=0;

robi:

(in /Users/kalek/rubydev/photos)
== CreateSlideshows: reverting ===============================================
– drop_table(“slideshows”)
-> 0.1104s
== CreateSlideshows: reverted (0.1107s) ======================================

ale ja jeszcze dodalem sobie migracje add_photo_columns ktora mi pomija i nie wiem czemu
class AddPhotoColumns < ActiveRecord::Migration
def self.up
add_column “photos”, “created_at”, :date
add_column “photos”, “thumbnail”, :string
add_column “photos”, “description”, :string
Photo.find(:all).each do |photo|
photo.update_attribute :created_at, Time.now
photo.update_attribute :thumbnail, photo.filename.gsub(’.’, ‘_m’)
end
end

def self.down
remove_column “photos”, “created_at”
remove_column “photos”, “thumbnail”
remove_column “photos”, “description”
end
end

moze ktos z was wie jak rozwiazac ten problem ?? bylbym wdzieczny bardzo

Albo inaczej utworzylem sobie migracje: 20090809205534_add_photo_columns za pomoca ruby script/generate migration add_photo_columns
jej kod to :

class AddPhotoColumns < ActiveRecord::Migration
def self.up
add_column :photos, :created_at, :date
add_column :photos, :thumbnail, :string
add_column :photos, :description, :string
Photo.find(:all).each do |photo|
photo.update_attribute :created_at, Time.now
photo.update_attribute :thumbnail, photo.filename.gsub(’.’, ‘_m’)
end
end

def self.down
remove_column “photos”, “created_at”
remove_column “photos”, “thumbnail”
remove_column “photos”, “description”
end
end

jak moge wykonac tylko ja czytalem ze podajac wersje ale i tak wypluwa mi jak robie : rake db:migrate VERSION=20090809205534

blad: Mysql::Error: Table ‘slides’ already exists: CREATE TABLE slides

Pomozcie bo cos nie wiem chyba o co chodzi

jeśli dobrze zrozumiałem, Twój problem może być taki: slides i slideshows to dwie różne rzeczy. Być może utworzyłeś tabelę (slides), która nie została uwzględniona (lub nie do końca właściwie) w migracjach i przy zmigrowaniu do wersji 0 nie zostaje ona usunięta. Dobrym początkiem rozwiązania problemu byłoby ustalenie jakie tabele są w bazie.

Tabele mam wszystkie w bazie:

mysql> show tables;
±-----------------------------+
| Tables_in_photos_development |
±-----------------------------+
| categories |
| categories_photos |
| photos |
| schema_migrations |
| slides |
| slideshows |
±-----------------------------+

Chodzi mi o to ze nie chce mi dodac 3 kolumn do tabeli photos

Dokladnie nie chce mi zrobic tej migracji ale za cholere nie wiem czemu , moze ktos z was bedzie mial jakies sugestie ,

class AddPhotoColumns < ActiveRecord::Migration
def self.up
add_column :photos, :created_at, :date
add_column :photos, :thumbnail, :string
add_column :photos, :description, :string
Photo.find(:all).each do |photo|
photo.update_attribute :created_at, Time.now
photo.update_attribute :thumbnail, photo.filename.gsub(’.’, ‘_m’)
end
end

def self.down
remove_column “photos”, “created_at”
remove_column “photos”, “thumbnail”
remove_column “photos”, “description”
end
end

i ta migracja sie nie odpala nie wiem czemu ???

jestem poczatkujacym

Wiec tak

Zrobilem sobie ze w schema.rb wpisalem sobie VERSION=0 i mam taki kod aby mi kiedy zrobie rake db:reset tworzyl wszystkie potrzebne tabele

This file is auto-generated from the current state of the database. Instead of editing this file,

please use the migrations feature of Active Record to incrementally modify your database, and

then regenerate this schema definition.

Note that this schema.rb definition is the authoritative source for your database schema. If you need

to create the application database on another system, you should be using db:schema:load, not running

all the migrations from scratch. The latter is a flawed and unsustainable approach (the more migrations

you’ll amass, the slower it’ll run and the greater likelihood for issues).

It’s strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 0) do

create_table “categories”, :force => true do |t|
t.string “name”
t.integer “parent_id”
end

create_table “categories_photos”, :id => false, :force => true do |t|
t.integer “category_id”
t.integer “photo_id”
end

create_table “photos”, :force => true do |t|
t.string “filename”
end

create_table “slides”, :force => true do |t|
t.integer “position”
t.integer “photo_id”
t.integer “slideshow_id”
end

create_table “slideshows”, :force => true do |t|
t.string “name”
t.date “created_at”
end

end

ale i tak nie wykonuje mi tej migracji gdzie chce zeby dodawal 3 kolumny do tabeli photos , dokladnie ten kod

class AddPhotoColumns < ActiveRecord::Migration
def self.up
add_column :photos, :created_at, :date
add_column :photos, :thumbnail, :string
add_column :photos, :description, :string
Photo.find(:all).each do |photo|
photo.update_attribute :created_at, Time.now
photo.update_attribute :thumbnail, photo.filename.gsub(’.’, ‘_m’)
end
end

def self.down
remove_column “photos”, “created_at”
remove_column “photos”, “thumbnail”
remove_column “photos”, “description”
end
end

po wykonanie rake db:reset mam takie cos:

damian-kaleks-computer:photos kalek$ rake db:reset
(in /Users/kalek/rubydev/photos)
– create_table(“categories”, {:force=>true})
-> 0.3335s
– create_table(“categories_photos”, {:force=>true, :id=>false})
-> 0.0705s
– create_table(“photos”, {:force=>true})
-> 0.0909s
– create_table(“slides”, {:force=>true})
-> 0.0895s
– create_table(“slideshows”, {:force=>true})
-> 0.0892s
– initialize_schema_migrations_table()
-> 0.3313s
– assume_migrated_upto_version(0)
-> 0.0021s
damian-kaleks-computer:photos kalek$

Nie wiem czemu pomija mi jedna migracje z tym dodawaniem kolumn wie ktos moze , pleseeeee ???

Wyczytalem tez ze mozna podac ktora migracje chce sie wykonac i jaka czesc np - rake db:migrate:up VERSION=20090811221223

i teraz dodaje ladnie 3 kolumny ale czemu nie robi tego przy resecie nie wiem , ma ktos jakis pomysl , dla mnie hmm dziwne to :slight_smile:

Jeszcze jeden problem , kiedy juz mam zapelniona tabele photos , to robiac

damian-kaleks-computer:photos kalek$ rake db:migrate:up VERSION=20090811221223
(in /Users/kalek/rubydev/photos)
damian-kaleks-computer:photos kalek$

to nic sie nie dzieje , kurde juz nie wiem jak ja mam to zrobic , pomozcie