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