Advertisement
Guest User

Untitled

a guest
Apr 16th, 2014
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #controller
  2. class TopicsController < ApplicationController
  3.   before_action :set_topic, only: [:show, :edit, :update, :destroy]
  4.  
  5.   # GET /topics
  6.   # GET /topics.json
  7.   def index
  8.     @topics = Topic.all
  9.   end
  10.  
  11.   # GET /topics/1
  12.   # GET /topics/1.json
  13.   def show
  14.   end
  15.  
  16.   # GET /topics/new
  17.   def new
  18.     @topic = Topic.new
  19.   end
  20.  
  21.   # GET /topics/1/edit
  22.   def edit
  23.   end
  24.  
  25.   # POST /topics
  26.   # POST /topics.json
  27.   def create
  28.     @topic = Topic.new(params[:topic])
  29.     if @topic.save
  30.       @topic = Topic.new(:name => params[:topic][:name], :last_poster_id => 1, :last_post_at => Time.now, :forum_id => params[:topic][:forum_id])
  31.  
  32.       if @topic.posts.first.save
  33.         flash[:notice] = "Successfully created topic."
  34.         redirect_to "/forums/#{@topic.forum_id}"
  35.       else
  36.         redirect :action => 'new'
  37.       end
  38.     else
  39.       render :action => 'new'
  40.     end
  41.   end
  42.  
  43.   # PATCH/PUT /topics/1
  44.   # PATCH/PUT /topics/1.json
  45.   def update
  46.     respond_to do |format|
  47.       if @topic.update(topic_params)
  48.         format.html { redirect_to @topic, notice: 'Topic was successfully updated.' }
  49.         format.json { head :no_content }
  50.       else
  51.         format.html { render action: 'edit' }
  52.         format.json { render json: @topic.errors, status: :unprocessable_entity }
  53.       end
  54.     end
  55.   end
  56.  
  57.   # DELETE /topics/1
  58.   # DELETE /topics/1.json
  59.   def destroy
  60.     @topic.destroy
  61.     respond_to do |format|
  62.       format.html { redirect_to topics_url }
  63.       format.json { head :no_content }
  64.     end
  65.   end
  66.  
  67.   private
  68.     # Use callbacks to share common setup or constraints between actions.
  69.     def set_topic
  70.       @topic = Topic.find(params[:id])
  71.     end
  72.  
  73.     # Never trust parameters from the scary internet, only allow the white list through.
  74.     def topic_params
  75.       params.require(:topic).permit(:name, :last_poster_id, :last_post_at)
  76.     end
  77. end
  78.  
  79. #_form
  80.  
  81. <% form_for @topic do |f| %>
  82.  
  83.     <% @topic.errors.full_messages.each do |msg| %>
  84.         <p><%= msg %></p>
  85.     <% end %>
  86.  
  87.     <% if params[:forum] %><input type="hidden" id="topic_forum_id" name="topic[forum_id]" value="<%= params[:forum] %>" /><% end %>
  88.     <p>
  89.         <%= f.label :name %><br />
  90.         <%= f.text_field :name %>
  91.     </p>
  92.     <p>
  93.         <%= f.text_area(:post, :content, size: "20x30") %>
  94.     </p>
  95.     <p><%= f.submit "Create" %></p>
  96. <% end %>
  97.  
  98. #error
  99.  
  100. Showing D:/Programacion/pfg/app/views/topics/_form.html.erb where line #13 raised:
  101.  
  102. wrong number of arguments (3 for 1..2)
  103. Extracted source (around line #13):
  104. 10
  105. 11
  106. 12
  107. 13
  108. 14
  109. 15
  110. 16
  111.          
  112.            <%= f.text_field :name %>
  113.        </p>
  114.        <p>
  115.            <%= f.text_area(:post, :content, size: "20x30") %>
  116.        </p>
  117.        <p><%= f.submit "Create" %></p>
  118.    <% end %>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement