Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #controller
- class TopicsController < ApplicationController
- before_action :set_topic, only: [:show, :edit, :update, :destroy]
- # GET /topics
- # GET /topics.json
- def index
- @topics = Topic.all
- end
- # GET /topics/1
- # GET /topics/1.json
- def show
- end
- # GET /topics/new
- def new
- @topic = Topic.new
- end
- # GET /topics/1/edit
- def edit
- end
- # POST /topics
- # POST /topics.json
- def create
- @topic = Topic.new(params[:topic])
- if @topic.save
- @topic = Topic.new(:name => params[:topic][:name], :last_poster_id => 1, :last_post_at => Time.now, :forum_id => params[:topic][:forum_id])
- if @topic.posts.first.save
- flash[:notice] = "Successfully created topic."
- redirect_to "/forums/#{@topic.forum_id}"
- else
- redirect :action => 'new'
- end
- else
- render :action => 'new'
- end
- end
- # PATCH/PUT /topics/1
- # PATCH/PUT /topics/1.json
- def update
- respond_to do |format|
- if @topic.update(topic_params)
- format.html { redirect_to @topic, notice: 'Topic was successfully updated.' }
- format.json { head :no_content }
- else
- format.html { render action: 'edit' }
- format.json { render json: @topic.errors, status: :unprocessable_entity }
- end
- end
- end
- # DELETE /topics/1
- # DELETE /topics/1.json
- def destroy
- @topic.destroy
- respond_to do |format|
- format.html { redirect_to topics_url }
- format.json { head :no_content }
- end
- end
- private
- # Use callbacks to share common setup or constraints between actions.
- def set_topic
- @topic = Topic.find(params[:id])
- end
- # Never trust parameters from the scary internet, only allow the white list through.
- def topic_params
- params.require(:topic).permit(:name, :last_poster_id, :last_post_at)
- end
- end
- #_form
- <% form_for @topic do |f| %>
- <% @topic.errors.full_messages.each do |msg| %>
- <p><%= msg %></p>
- <% end %>
- <% if params[:forum] %><input type="hidden" id="topic_forum_id" name="topic[forum_id]" value="<%= params[:forum] %>" /><% end %>
- <p>
- <%= f.label :name %><br />
- <%= f.text_field :name %>
- </p>
- <p>
- <%= f.text_area(:post, :content, size: "20x30") %>
- </p>
- <p><%= f.submit "Create" %></p>
- <% end %>
- #error
- Showing D:/Programacion/pfg/app/views/topics/_form.html.erb where line #13 raised:
- wrong number of arguments (3 for 1..2)
- Extracted source (around line #13):
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- <%= f.text_field :name %>
- </p>
- <p>
- <%= f.text_area(:post, :content, size: "20x30") %>
- </p>
- <p><%= f.submit "Create" %></p>
- <% end %>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement