Projeto: Vermelho

logs of development
スポンサーサイト

一定期間更新がないため広告を表示しています

| - | | - | -
[Rails]アソシエーションの関係にあるmodelをnestした場合の、createでエラーしたときのrenderの記述
やっと分かった(T_T).

controller:
def new @user = User.find(params[:user_id])
  @message = @user.messages.build
end

def create
  @user = User.find(params[:user_id])
  @message = @user.messages.new(params[:message])

  if @message.save
    flash[:notice] = 'Message saved'
    redirect_to user_url(@user)
  else
    render :action => "new" # Here is the problem I guess
  end
end
view:
<% form_for [@user, @message] do |f| %>
  <%= f.error_messages %>
  Name:<%= f.text_field :name %>
  Email:<%= f.text_field :email %>
  Message:<%= f.text_area :body, :rows => 3 %>
  <%= f.submit 'Send' %>
<% end %>
| Pg_Rails | 23:28 | comments(0) | trackbacks(0)
fill_inを使ったステップでCapybara::ElementNotFound
cucumberでフォームを埋めるシナリオをテストするのだが、どうしても、fill_inでfailerになって進まない.なぜ?

Then I fill in "message" with "good"

cannot fill in, no text field, text area or password field with id, name, or label 'message' found (Capybara::ElementNotFound)
      (eval):2:in `fill_in'
      ./features/step_definitions/web_steps.rb:61:in `/^(?:|I )fill in "([^"]*)" with "([^"]*)"$/'
      features/manage_objects.feature:9:in `And I fill in "message" with "good"'

テキストエリア等について、id, name, or labelを使えと言っている.使ってるじゃん.と思いながら、解決を探していたら、こんな解説見っけ.

テキストフィールドやsubmiボタンの名前をブラウザのソースでみつけたid名にしたみたわけなんだけど。
http://michitoshi.blogspot.com/2010/12/cucumbermessagefeaturerails3.html

ん!?ブラウザでチェック?
同じことをしてみたら…テキストエリアにIDが着いてて、"model_fieldname"になってる(^_^;.知らなかった….
その名前を使ってステップを書き直した.

Then I fill in "object_massage" with "good"

通りました(T_T).
| cucumber | 17:57 | comments(0) | trackbacks(0)
Ambiguous match of ...
web_steps.rbにすでに存在する場合はあらためて書く必要ないらしい
http://markmail.org/message/qekq3itofdv2ikbj
    Given I am on the new moso page   # features/manage_mosos.feature:7
      Ambiguous match of "I am on the new object page":
     
      features/step_definitions/moso_steps.rb:1:in `/^(?:|I )am on (.+)$/'
      features/step_definitions/web_steps.rb:44:in `/^(?:|I )am on (.+)$/'
     
      You can run again with --guess to make Cucumber be more smart about it
       (Cucumber::Ambiguous)
      features/manage_mosos.feature:7:in `Given I am on the new moso page'

    And I press "Create"              # features/manage_mosos.feature:10
      Ambiguous match of "I press "Create"":
     
      features/step_definitions/moso_steps.rb:9:in `/^I press "([^"]*)"$/'
      features/step_definitions/web_steps.rb:52:in `/^(?:|I )press "([^"]*)"$/'
     
      You can run again with --guess to make Cucumber be more smart about it
       (Cucumber::Ambiguous)
      features/manage_mosos.feature:10:in `And I press "Create"'

| cucumber | 07:21 | comments(0) | trackbacks(0)
cucumber: featureファイルの生成
$ rails g cucumber:feature models
       exist  features/step_definitions
      create  features/manage_models.feature
      create  features/step_definitions/models_steps.rb
        gsub  features/support/paths.rb

| Pg_Rails | 01:07 | comments(1) | trackbacks(0)
cucumber: web検証のエンジンにcapybaraを指定してインストール
 $ rails g cucumber:install ja --rspec --capybara
| Pg_Rails | 00:51 | comments(0) | trackbacks(0)
add_columnしたときには:null=>falseはできません
 http://strd6.com/2009/04/adding-a-non-null-column-with-no-default-value-in-a-rails-migration/
| - | 18:29 | comments(0) | trackbacks(0)
“File not found: lib” error while installing Rails 3.0.9 for MacOSX, RVM, Ruby1.9.2
評価:
David Thomas,Andrew Hunt
Addison-Wesley Pub (Sd)
¥ 3,634
(2000-12-15)

 Ruby1.9.2, RVM, MacOSX(Snow Leoperd)にRails3.0.9をインストールしたところ.ログに“File not found: lib”がでた.気持ち悪いのでしらべたら、1.9.2のフォルダがないことが要因のよう.

以下のように対処

$ gem install rdoc-data
$ cp -pR /Users/username/.rvm/gems/ruby-1.9.2-p180/gems/rdoc-data-2.5.3/data/1.9.1 /Users/username/.rvm/gems/ruby-1.9.2-p180/gems/rdoc-data-2.5.3/data/1.9.2
$ rdoc-data --install
$ gem rdoc --all --overwrite
$ mkdir /Users/username/.rvm/gems/ruby-1.9.2-p180/gems/rails-3.0.9/lib
$ gem install rails

参考
‘File not found: lib’ Error installing Rails Gem

“File not found: lib” error while installing Rails 3.0.7

Ruby1.9.2でrdoc-data –install出来ない件について

gem install railsでFile not found: lib
| Pg_Ruby | 05:23 | comments(1) | trackbacks(0)
PROFILE
CATEGORIES
LINKS
CALENDAR
S M T W T F S
     12
3456789
10111213141516
17181920212223
24252627282930
31      
<< July 2011 >>
SELECTED ENTRIES
ARCHIVES
モバイル
qrcode
SPONSORED LINKS