Ask A Question

Notifications

You’re not receiving notifications from this thread.

Rails for Beginners Part 30: Tweet Validations Discussion

Working these videos late, I failed to realize my timezone is different from the rails default. You can set your time zone in config/application.rb.

For example:
config.time_zone = "Eastern Time (US & Canada)"

There is a lot written about automatic detection of time zones:

GoRails.com search
https://gorails.com/episodes/forum-time-zones-with-local_time
https://gorails.com/episodes/auto-detect-user-time-zones-in-rails

Other search results
https://stackoverflow.com/questions/6280872/auto-detect-users-timezone-using-his-ip-in-rails

Reply

When trying to render the partial on /tweets/new, I'm getting the error:

```NoMethodError in Tweets#new

Showing /Users/ianmcmullen/scheduled_tweets/app/views/shared/_form_errors.html.erb where line #1 raised:

undefined method errors' for nil:NilClass``

However, the same line — <%= render "shared/form_errors", form: form %> — is working fine in registrations/new and giving the errors as expected. Is there anything I may be missing?

Reply

I was using the variable "Tweets" instead of "tweets", got that part sorted!

Reply

I was having an issue where the new Tweet form would not submit. It seems like it is being caused by the "Connect Another Twitter Account" button. In the tutorial this is a link_to but now with OmniAuth 2. 0 this has to be a button_to with a POST request, which seems to stop the form working. I assume it conflicts with the POST of the form itself.

Can anyone give advice on how to maintain this "Connect Another Twitter Account" functionality? For now I have had to remove the button entirely

Reply

if error partial is not rendering add the following code to the form:
<%= form_with model: @tweet, data: { turbo: false }, local: true do |form| %>

Reply

Thanks, this helped be get unstuck. Apparently, link_to and button_to has to do with Hotwire, which I have not learnt at this point. Will have come back and understand why once I learn that.

Reply

Other solution if errors partial is not rendering

def create
@tweet = Current.user.tweets.new(tweet_params)
if @tweet.save
redirect_to tweets_path, notice: "Tweet was scheduled successfully"
else
render :new, status: :unprocessable_entity
end
end

Reply

My form does not submit...
I added <%= form_with model: @tweet, data: { turbo: false }, local: true do |form| %>
which solved the issue but it seems like it treats the link_to link as the submit button for the form so it closes the form leaving the rest of the fields out. Therefore on submit, it will not submit. I removed this link and it works. Any Idea why would it be treating it as the end of the form?

I also had to change the link_to to button_to for it to work, since omniath 2.0, other wise it says the path auth/tweet does not exists, changing this button to link_to solves my form issue but now the link is useless, any Idea on how can I fix this?

Reply

if you are getting the error:

undefined local variable or method `form' for #<ActionView::Base:0x00000000024720>

make sure you don't include partial in the render (like you would with the navbar)

<%= render "shared/form_errors", form: form %>
Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 82,464+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.