質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Q&A

解決済

1回答

2447閲覧

選択リストの作成時にcontrollers.rbに構文エラーが出る。

Tikka

総合スコア11

Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

0グッド

0クリップ

投稿2017/11/01 13:50

選択リストの作成時にcontrollers.rbに構文エラーが出る。

Controllers.rbの全文
class TikkaController < ApplicationController

def index if request.post? then @title = "Result" if params["s1"] then @msg = "you selected: " + "params["s1"] else @msg = "not selected..." end else @title = "index" @msg = "select List..." end end

end

index.html.erbの全文

<h1><%= @title %></h1> <p><%= @msg %></p> <%= form_tag(controller: "tikka",action: "index") do %> <%= serect_tag("s1", options_for_select(["Windows", "macOS", "Linux"])) %> <%= submit_tag("Click") %> <% end %>

エラー全文
Started GET "/tikka" for 127.0.0.1 at 2017-11-01 22:43:40 +0900
C:/Users/Admin/Ruby22-x64/RailsApp/app/controllers/tikka_controller.rb:12: warning: string literal in condition

SyntaxError (C:/Users/Admin/Ruby22-x64/RailsApp/app/controllers/tikka_controller.rb:7: syntax error, unexpected tIDENTIFIER, expecting keyword_end
@msg = "you selected: " + "params["s1"]
^
C:/Users/Admin/Ruby22-x64/RailsApp/app/controllers/tikka_controller.rb:9: syntax error, unexpected keyword_not, expecting keyword_end
@msg = "not selected..."
^
C:/Users/Admin/Ruby22-x64/RailsApp/app/controllers/tikka_controller.rb:12: syntax error, unexpected tIDENTIFIER, expecting keyword_end
@title = "index"
^
C:/Users/Admin/Ruby22-x64/RailsApp/app/controllers/tikka_controller.rb:13: syntax error, unexpected tIDENTIFIER, expecting keyword_end
@msg = "select List..."
^
C:/Users/Admin/Ruby22-x64/RailsApp/app/controllers/tikka_controller.rb:13: unterminated string meets end of file
C:/Users/Admin/Ruby22-x64/RailsApp/app/controllers/tikka_controller.rb:13: syntax error, unexpected end-of-input, expecting keyword_end):

app/controllers/tikka_controller.rb:7: syntax error, unexpected tIDENTIFIER, expecting keyword_end
app/controllers/tikka_controller.rb:9: syntax error, unexpected keyword_not, expecting keyword_end
app/controllers/tikka_controller.rb:12: syntax error, unexpected tIDENTIFIER, expecting keyword_end
app/controllers/tikka_controller.rb:13: syntax error, unexpected tIDENTIFIER, expecting keyword_end
app/controllers/tikka_controller.rb:13: unterminated string meets end of file
app/controllers/tikka_controller.rb:13: syntax error, unexpected end-of-input, expecting keyword_end

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

コード部を選択して上の</>みたいなボタンを押してみてください。
そうするとわかります。

ruby

1class TikkaController < ApplicationController 2 3 def index 4 if request.post? then 5 @title = "Result" 6 if params["s1"] then 7 @msg = "you selected: " + "params["s1"] 8 else 9 @msg = "not selected..." 10 end 11 else 12 @title = "index" 13 @msg = "select List..." 14 end 15 end 16 17end

こうすることで色が変わりどこからおかしいのかがわかりやすくなりましたよね?

ruby

1@msg = "you selected: " + "params["s1"]

この行のparamsの前のダブルクォーテーションは不必要です。

投稿2017/11/02 00:20

chelsy7110

総合スコア596

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問