New to RoR; I have received great help here.
Moving through a tutorial here, and I created a new controller. However, the config/routes file did not automatically update. Therefor, I made the edit myself and added get "static_pages/home" and get "static_pages/help". However, when I go to the url for the 'Home' page, I'm presented with and error stating:
SyntaxError in StaticPagesController#home
further stating:
/Users/coreymkimball/Canvi/sample_app/app/controllers/static_pages_controller.rb:2: syntax error, unexpected rails.root: /Users/coreymkimball/Canvi/sample_app
Can anyone give me a tip?
Actually i am not familiar in this .but you can refer this links.....hope this link will helpful.
Hartl Tutorial: 3.2 Error when i try and clean up my code
displaying two renders in staticpage home in rails 3
Related
I'm a newbie for RoR 3, i have followed instruction from Simple Rails 2 book. I got NoMethodError in browser but when i tried from Console, it works without any error. Can any one help me ?
My full Code can view at Github : https://github.com/iamkevinhuang/shovel/
Error in Browser :
Work in Console :
Can anyone help me ?
Please put action show out site protected block. Example put it in line 11
I followed the https://www.sitepoint.com/rails-and-actioncable-adding-advanced-features tutorial, but it says:
NameError in PersonalMessagesController#create uninitialized constant
PersonalMessage::NotificationBroadcastJob
after_create_commit do
conversation.touch
NotificationBroadcastJob.perform_later(self)
end
end
The above error appears when I submit, but when I go back I get a message.
So I deleted code:
after_create_commit do
conversation.touch
NotificationBroadcastJob.perform_later(self)
end
end
and tried to run it. I did not see the same error, but this time I can not chat live.
I followed the tutorial faithfully. I do not know why two problems arise. I need help.
my github : https://github.com/sangyeol-kim/stackoverflow_ask_ac2
Try fixing file name notifications_broadcast_job.rb -> notification_broadcast_job.rb
My Rails 3.2.9-app does not show any specific error information to me on errors in templates! It doesn't matter if I use haml or erb, I am always getting
"We're sorry, but something went wrong"
In fact, Webrick is in development mode and if there are errors in my models or controllers, I get the full ordinary error screen.
Examples
Example error in my helper-template ("#resource" does not exist, must be "resource"):
-> All I get is this lousy "We are sorry, but something went wrong"
<% #resource.errors.full_messages.each do |msg| %>
Example error in one of my controllers:
resposnd_to do |format|
-> undefined method `resposnd_to' for ...
I finally solved this problem!! All in all, I searched for more than 1 year, but now, i finally got the solution:
The problem is to use umlauts or blank spaces in the path of the rails project. If you move your rails project to a path without umlauts or blanks, the error message should be shown properly :-)!
Tested on ubuntu-machine, maybe this is important for this bug. This bug appears in rails 3.2.9, 3.2.13 and 3.2.14 definitely.
(consider_all_requests_local is activated of course, this never was the reason)
Context:
I pulled the most recent code from the repository and tried to make sure that the changes I was about to push up were going to work with that version of the code. This is a Ruby on Rails application. Also worth noting is the fact that when running the main application that I pulled from on the web, this error does not show up. But if I run my branch or the main branch cloned onto my environment, the error always shows up for every url I try. So it is on my end.
Problem:
As soon as I go to localhost:3000, I get the following error:
NoMethodError in HomeController#index
undefined method `-#' for #<ActionDispatch::Response:0x64fd460>
What I've Tried:
I have asked my question on the #rubyonrails IRC channel and nobody was able to determine what was going on through the Full Trace (I haven't posted it here because I wasn't sure what was the best way to do that on here; it didn't look very good in the code block or block quote). I have looked at my HomeController's index method, which is defined as such:
def index
#groups = #current_user.groups
#things = Thing.where(:group_id => #groups.map{|e|e.id})
end
I have also Googled around and haven't found what I need to fix the problem.
What I've Learned So Far:
-# is an operator. Some people may receive a similar error in assuming that Ruby has the shortcut to
variable = variable + 1
that a lot of other languages have:
variable++
Here is an example of that case: Undefined method `+#' for false:FalseClass (NoMethodError) ruby
Question:
Does anyone have any further suggestions on how to find the issue here? Also, if I could easily put the Full Trace on here, formatted in an aesthetically pleasing manner, would someone tell me how? I'm at a loss with this one :(
Update (2/8/2013):
It seems that the issue does not necessarily reside in the HomeController nor home/index.html.erb View. I have attempted to access ANY url with a valid action and the same error occurs with "NoMethodError in..." changing to the corresponding [...]Controller#index.
Update (2/9/2013):
Since this error happens no matter what url I try to navigate to, I decided to look in the routes.rb file in the config folder. I ran my server through rubymine instead of the command line this time, which made it a little easier to read for me. I started looking through all the spit out and I noticed an interested line that consisted of:
["private-key looking thing"] [127.0.0.1] Started GET "/" for 127.0.0.1 at 2013-02-09 18:20:52 -0700
It seems like there is a syntactical error in routes.rb (that's my best guess at this point). This does not explain why this only is an issue on my local environment with the same code sets, but what else do I have to go off of?
Does anyone have any suggested things to be on the look out for while I sift through this file? Not really sure what to be looking for as far as errors are concerned. Rubymines inspection stuff converted all my double quotes to single quotes and doesn't really have anything else to complain about.
Thanks in advance,
Jake Smith
I am guessing it might as well be an syntactical error in the corresponding view page Home/index.html.haml .. I am suspecting there is unintended '-' in front of variable call. I tried to simulate a similar scenario in my rails platform and see following page on browser
undefined method `-#' for false:FalseClass
Correct lines of code
%h1 All Movies
= "filtervalue=#{#isFilterOld}"
= "Sortvalue=#{#isSortOld}"
Edited to simulate the error (observe the - in front of isFilterOld variable)
%h1 All Movies
= "filtervalue=#{-#isFilterOld}"
= "Sortvalue=#{#isSortOld}"
I have fixed the issue!
What fixed it:
Go to the directory where your gems are (for me that was C:\RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1)
Delete all gems except for bundler
Make sure you delete the gems from the /cache/, /gems/, and /specifications/ folders (I just deleted them from the /gems/ folder at first and bundle install indicated that it could still find the gems)
Run bundle install
Further Inquiry:
Does anybody have any idea why this worked? I don't know if at this point I can narrow down which gem was causing the issue because the app is working now (I can visit all the urls with corresponding views). If the issue comes up again, I will delete gems one by one to nail down which one was at least causing the issue for me. But if anyone has any insight on this, a more detailed answer would be greatly appreciated by many more people than just me, I think. Thanks to all who helped thus far!
When I go to a bogus url like:
/posts/99999999
On my local machine, I see:
ActiveRecord::RecordNotFound in Posts#show
Showing /Users/patrick/rails/my_app/app/views/posts/show.html.haml where line #1 raised:
Couldn't find Post with ID=99999
... The log shows:
Rendered posts/show.html.haml within layouts/application (29.6ms)
Completed in 423ms
ActionView::Template::Error (Couldn't find Post with ID=99999)
--- However, when I do this in production, I get the public/500.html error page, not 404... I'm kind of confused because in development mode, the browser shows ActiveRecord::RecordNotFound (which should mean 404, yes?) but the log shows ActionView::Template::Error-- not one mention of ActiveRecord::RecordNotFound.
So, ultimately, my question is, how can I make this a 404 not a 500? And-- why is it a 500?
From what I have seen, Rails should automatically make an ActiveRecord::RecordNotFound render the 404.html page... The problem I discovered was I am using the gem decent_exposure, and because of it's nature of lazy loading, it causes the error to happen in the view rather than the controller, and therefore Rails doesn't know to render the 404 page because it shows up as an actual ActionView::Template::Error...
Just add a ! to the find_by_column method.
Example:
#post = Post.find_by_id!(params[:id])
Then, a RecordNotFound exception is thrown.