Nathan La Barbera
Joined
Activity
Posted in Error Handling in Ruby 4+
Jeff, thank you for the feedback. This worked perfectly and achieved everything I needed. Thank you again.
Posted in Error Handling in Ruby 4+
Perfect, great advice guys! Thank you for the feedback! I wanted to use the rescue_from method but couldn't get it to work. I'll look more into it and spend more time on it. Thanks again guys.
Posted in Error Handling in Ruby 4+
Does anyone have any thoughts or why this might be a bad practice?
I am using the following code as the last route within my routes.rb
get "*path", to: redirect('/')
It seems to handle very well if someone navigates to a URL that isn't valid rather then displaying the default Rails "Routing Error".
I am wanting to know if there is a better method and if this is standard practice.
Thanks everyone.
James, you are exactly correct. Thank you for the feedback and helping me.
Alright everyone, I would greatly appreciate your help solving this problem. Here is what I'm attempting to do; I have an articles controller and all the related views to create new article posts.
Articles Controller:
class ArticlesController < ApplicationController
def index
@articles = Article.all
end
def new
@article = Article.new
end
def create
@article = Article.new(
title: params[:article][:title],
body: params[:article][:body])
@article.save
redirect_to article_path(@article)
end
def show
@article = Article.find(params[:id])
end
end
This controller works fine when I go to a form that was generate by the scaffolding. I can navigate to articles/new and then fill the form out for a new article and it posts perfectly. Here is my dilemma, I have a separate view and controller for an admin page, and I want to be able to copy the form from the articles/new view into that admin/index view. For some reason I am having an issue posting to another controller from a separate view. Can someone please shed light on this, after spending countless hours over this weekend, you can imaging how frustrating this is getting :rage:
Admin Index:
<%= form_for @article do |f| %>
<ul>
<% @article.errors.full_messages.each do |error| %>
<li><%= error %></li>
<% end %>
</ul>
<p>
<%= f.label :title %><br />
<%= f.text_field :title %>
</p>
<p>
<%= f.label :body %><br />
<%= f.text_area :body %>
</p>
<p>
<%= f.submit %>
</p>
<% end %>
Admin Controller:
class AdminController < ApplicationController
def index
render layout: "admin_layout"
end
end
The error sign that I am getting when I navigate to localhost:3000/admin/index is: First argument in form cannot contain nil or be empty
Any help I could get from you more experience would be amazing. Thank you a ton in advanced! :joy:
Nathan